[Debtags-commits] [svn] r1748 - in tagcoll/2.0: . tagcoll/coll
Enrico Zini
enrico at costa.debian.org
Tue May 9 22:34:45 UTC 2006
Author: enrico
Date: Tue May 9 22:34:41 2006
New Revision: 1748
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/coll/fast.cc
tagcoll/2.0/tagcoll/coll/fast.h
Log:
r2674 at viaza: enrico | 2006-05-09 17:00:06 -0500
Implemented method from CardinalityStore into Fast
Modified: tagcoll/2.0/tagcoll/coll/fast.cc
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.cc (original)
+++ tagcoll/2.0/tagcoll/coll/fast.cc Tue May 9 22:34:41 2006
@@ -108,7 +108,7 @@
}
template<class ITEM, class TAG>
-std::set<TAG> Fast<ITEM, TAG>::getTagsImplying(const TAG& tag)
+std::set<TAG> Fast<ITEM, TAG>::getTagsImplying(const TAG& tag) const
{
// tag1 implies tag2 if the itemset of tag1 is a subset of the itemset of tag2
std::set<TAG> res;
@@ -150,6 +150,16 @@
tags.erase(itag);
}
+template<class ITEM, class TAG>
+Fast<ITEM, TAG> Fast<ITEM, TAG>::getChildCollection(const TAG& tag) const
+{
+ Fast<ITEM, TAG> res;
+ outputHavingTags(wibble::singleton(tag), inserter(res));
+ res.removeTag(tag);
+ return res;
+}
+
+
#if 0
template<class ITEM, class TAG>
@@ -256,6 +266,36 @@
ensure_coll_equals(result, coll);
}
+template<> template<>
+void to::test<5>()
+{
+ Fast<string, string> coll;
+ output_test_collection(inserter(coll));
+
+ set<string> ts;
+ ts.insert("tomato"); ts.insert("mozzarella");
+
+ set<string> items = coll.getCommonItems(ts);
+ ensure_equals(items.size(), 2u);
+ ensure_contains(items, string("margherita"));
+ ensure_contains(items, string("funghi"));
+
+ items = coll.getItemsExactMatch(ts);
+ ensure_equals(items.size(), 1u);
+ ensure_contains(items, string("margherita"));
+}
+
+template<> template<>
+void to::test<6>()
+{
+ Fast<string, string> coll;
+ output_test_collection(inserter(coll));
+
+ size_t card;
+ string tag = coll.findTagWithMaxCardinality(card);
+ ensure_equals(card, 3u);
+ ensure_equals(tag, "tomato");
+}
}
}
Modified: tagcoll/2.0/tagcoll/coll/fast.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.h (original)
+++ tagcoll/2.0/tagcoll/coll/fast.h Tue May 9 22:34:41 2006
@@ -106,6 +106,10 @@
bool hasTag(const TAG& tag) const { return tags.find(tag) != tags.end(); }
std::set<ITEM> getTaggedItems() const;
std::set<TAG> getAllTags() const;
+
+ unsigned int itemCount() const { return items.size(); }
+ unsigned int tagCount() const { return tags.size(); }
+
#if 0
void output(Consumer<ITEM, TAG>& consumer) const;
#endif
@@ -113,7 +117,42 @@
// tag1 implies tag2 if the itemset of tag1 is a subset of the itemset of
// tag2
- std::set<TAG> getTagsImplying(const TAG& tag);
+ std::set<TAG> getTagsImplying(const TAG& tag) const;
+
+ // Return the items which have the exact tagset 'tags'
+ std::set<ITEM> getItemsExactMatch(const std::set<TAG>& tags) const
+ {
+ std::set<ITEM> res = getCommonItems(tags);
+ typename std::set<ITEM>::iterator i = res.begin();
+ while (i != res.end())
+ {
+ typename std::map<ITEM, std::set<TAG> >::const_iterator t = items.find(*i);
+ if (t != items.end() && t->second != tags)
+ {
+ typename std::set<ITEM>::iterator j = i;
+ ++i;
+ res.erase(j);
+ } else
+ ++i;
+ }
+ return res;
+ }
+
+ TAG findTagWithMaxCardinality(size_t& card) const
+ {
+ card = 0;
+ TAG res;
+ for (typename std::map<TAG, std::set<ITEM> >::const_iterator i = tags.begin();
+ i != tags.end(); ++i)
+ if (i->second.size() > card)
+ {
+ card = i->second.size();
+ res = i->first;
+ }
+ return res;
+ }
+
+ Fast<ITEM, TAG> getChildCollection(const TAG& tag) const;
void removeTag(const TAG& tag);
};
More information about the Debtags-commits
mailing list