[Debtags-commits] [svn] r1997 - in tagcoll/2.0: . tagcoll/coll
Enrico Zini
enrico at costa.debian.org
Wed Oct 4 23:17:27 UTC 2006
Author: enrico
Date: Wed Oct 4 23:17:26 2006
New Revision: 1997
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/coll/base.h
tagcoll/2.0/tagcoll/coll/base.tcc
Log:
r3502 at viaza: enrico | 2006-10-05 01:16:02 +0200
Added sorting by cardinality
Modified: tagcoll/2.0/tagcoll/coll/base.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/base.h (original)
+++ tagcoll/2.0/tagcoll/coll/base.h Wed Oct 4 23:17:26 2006
@@ -48,6 +48,18 @@
{
const Self& self() const { return *static_cast<const Self*>(this); }
+ class CardinalityOrder
+ {
+ const Self& coll;
+ public:
+ CardinalityOrder(const Self& coll) : coll(coll) {}
+ bool operator()(const typename coll_traits<Self>::tag_type& t1, const typename coll_traits<Self>::tag_type& t2)
+ {
+ // Returns true if t1 precedes t2, and false otherwise
+ return coll.getCardinality(t1) < coll.getCardinality(t2);
+ }
+ };
+
class DiscriminanceOrder
{
const Self& coll;
@@ -229,6 +241,12 @@
/**
* Get a vector containing all tags in this collection, sorted by
+ * increasing cardinality
+ */
+ std::vector<typename coll_traits<Self>::tag_type> tagsInCardinalityOrder() const;
+
+ /**
+ * Get a vector containing all tags in this collection, sorted by
* increasing discriminance value (@see getDiscriminance)
*/
std::vector<typename coll_traits<Self>::tag_type> tagsInDiscriminanceOrder() const;
Modified: tagcoll/2.0/tagcoll/coll/base.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/coll/base.tcc (original)
+++ tagcoll/2.0/tagcoll/coll/base.tcc Wed Oct 4 23:17:26 2006
@@ -156,6 +156,14 @@
}
template<typename Self>
+std::vector<typename coll_traits<Self>::tag_type> ReadonlyCollection<Self>::tagsInCardinalityOrder() const
+{
+ std::vector<typename coll_traits<Self>::tag_type> res = self().getAllTagsAsVector();
+ std::sort(res.begin(), res.end(), CardinalityOrder(self()));
+ return res;
+}
+
+template<typename Self>
std::vector<typename coll_traits<Self>::tag_type> ReadonlyCollection<Self>::tagsInDiscriminanceOrder() const
{
std::vector<typename coll_traits<Self>::tag_type> res = self().getAllTagsAsVector();
More information about the Debtags-commits
mailing list