[Debtags-commits] [svn] r948 - libtagcoll1/trunk/tagcoll
Enrico Zini
debtags-commits@lists.alioth.debian.org
Mon, 27 Jun 2005 17:49:58 +0000
Author: enrico
Date: Mon Jun 27 17:49:57 2005
New Revision: 948
Modified:
libtagcoll1/trunk/tagcoll/TDBDiskIndex.cc
libtagcoll1/trunk/tagcoll/TDBDiskIndex.h
libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.cc
libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.h
libtagcoll1/trunk/tagcoll/TagCollection.cc
libtagcoll1/trunk/tagcoll/TagCollection.h
libtagcoll1/trunk/tagcoll/TagcollBuilder.h
Log:
Added getCardinality to TDB*DiskIndex
Cleaned up the interface of TagCollection
Modified: libtagcoll1/trunk/tagcoll/TDBDiskIndex.cc
==============================================================================
--- libtagcoll1/trunk/tagcoll/TDBDiskIndex.cc (original)
+++ libtagcoll1/trunk/tagcoll/TDBDiskIndex.cc Mon Jun 27 17:49:57 2005
@@ -88,6 +88,12 @@
return serializer.stringsToItems(tagdb.getStringSet(""));
}
+template<class ITEM, class TAG>
+int TDBDiskIndex<ITEM, TAG>::getCardinality(const TAG& tag) const
+{
+ return tagdb.getStringSet(serializer.tagToString(tag)).size();
+}
+
static int collect_items(TDB_CONTEXT* db, TDB_DATA key, TDB_DATA val, void* data) throw ()
{
if (key.dsize >= 1)
Modified: libtagcoll1/trunk/tagcoll/TDBDiskIndex.h
==============================================================================
--- libtagcoll1/trunk/tagcoll/TDBDiskIndex.h (original)
+++ libtagcoll1/trunk/tagcoll/TDBDiskIndex.h Mon Jun 27 17:49:57 2005
@@ -109,6 +109,11 @@
virtual OpSet<TAG> getAllTags() const throw (SystemException);
/**
+ * Get the cardinality of a tag (that is, the number of items who have it)
+ */
+ virtual int getCardinality(const TAG& tag) const;
+
+ /**
* Send the data to a consumer
*/
virtual void output(TagcollConsumer<ITEM, TAG>& consumer) const throw (SystemException);
Modified: libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.cc
==============================================================================
--- libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.cc (original)
+++ libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.cc Mon Jun 27 17:49:57 2005
@@ -209,6 +209,25 @@
return res;
}
+
+template<class ITEM, class TAG>
+int TDBReadonlyDiskIndex<ITEM, TAG>::getCardinality(const TAG& tag) const
+{
+ int card = TDBDiskIndex<ITEM, TAG>::getCardinality(tag);
+
+ for (typename PatchList<ITEM, TAG>::const_iterator i = changes.begin();
+ i != changes.end(); i++)
+ {
+ if (i->second.getAdded().contains(tag))
+ card++;
+ else if (i->second.getRemoved().contains(tag))
+ card--;
+ }
+
+ return card;
+}
+
+
template<class ITEM, class TAG>
struct out_patched_data
{
Modified: libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.h
==============================================================================
--- libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.h (original)
+++ libtagcoll1/trunk/tagcoll/TDBReadonlyDiskIndex.h Mon Jun 27 17:49:57 2005
@@ -94,6 +94,11 @@
virtual OpSet<TAG> getTags(const ITEM& item) const throw ();
/**
+ * Get the cardinality of tag `tag' (that is, the number of items who have it
+ */
+ virtual int getCardinality(const TAG& tag) const;
+
+ /**
* Get the items with no tags
*/
virtual OpSet<ITEM> getUntaggedItems() const throw ();
Modified: libtagcoll1/trunk/tagcoll/TagCollection.cc
==============================================================================
--- libtagcoll1/trunk/tagcoll/TagCollection.cc (original)
+++ libtagcoll1/trunk/tagcoll/TagCollection.cc Mon Jun 27 17:49:57 2005
@@ -89,7 +89,7 @@
// Re-add the item with the new tagset
if (!newts.empty())
- add(newts, i->first);
+ consume(i->first, newts);
}
}
@@ -116,7 +116,7 @@
}
template<class ITEM, class TAG>
-void TagCollection<ITEM, TAG>::add(const ITEM& item) throw ()
+void TagCollection<ITEM, TAG>::consume(const ITEM& item) throw ()
{
#ifdef TRACE
fprintf(stderr, "Add untagged: %d\n", item);
@@ -125,7 +125,7 @@
}
template<class ITEM, class TAG>
-void TagCollection<ITEM, TAG>::add(const OpSet<ITEM>& items) throw ()
+void TagCollection<ITEM, TAG>::consume(const OpSet<ITEM>& items) throw ()
{
#ifdef TRACE
fprintf(stderr, "Add untagged: %d items\n", items.size());
@@ -137,7 +137,7 @@
}
template<class ITEM, class TAG>
-void TagCollection<ITEM, TAG>::add(const OpSet<TAG>& tagset, const ITEM& item) throw ()
+void TagCollection<ITEM, TAG>::consume(const ITEM& item, const OpSet<TAG>& tagset) throw ()
{
if (tagset.size() == 0)
return;
@@ -166,7 +166,7 @@
}
template<class ITEM, class TAG>
-void TagCollection<ITEM, TAG>::add(const OpSet<TAG>& tagset, const OpSet<ITEM>& items) throw ()
+void TagCollection<ITEM, TAG>::consume(const OpSet<ITEM>& items, const OpSet<TAG>& tagset) throw ()
{
if (tagset.size() == 0 || items.size() == 0)
return;
@@ -385,9 +385,9 @@
// Check if we make orphans, and preserve them
if (newts.size() == 0 && ts->second.size() > 0)
- res.add(ts->second);
+ res.consume(ts->second);
else
- res.add(newts, ts->second);
+ res.consume(ts->second, newts);
}
return res;
}
@@ -459,11 +459,11 @@
{
// Insert the newfound tagset in the new collection
//res.add(newts, ts->second);
- res.add(ts->first, ts->second);
+ res.consume(ts->second, ts->first);
}
}
if (untagged.size() > 0)
- res.add(untagged);
+ res.consume(untagged);
return res;
}
@@ -479,10 +479,10 @@
// For all tagsets that do not contain tag
// Insert the selected tagset in the new collection
- res.add(ts->first, ts->second);
+ res.consume(ts->second, ts->first);
}
if (untagged.size() > 0)
- res.add(untagged);
+ res.consume(untagged);
return res;
}
@@ -499,10 +499,10 @@
// For all tagsets that do not contain some of the tags in `tag`
// Insert the selected tagset in the new collection
- res.add(ts->first, ts->second);
+ res.consume(ts->second, ts->first);
}
if (untagged.size() > 0)
- res.add(untagged);
+ res.consume(untagged);
return res;
}
Modified: libtagcoll1/trunk/tagcoll/TagCollection.h
==============================================================================
--- libtagcoll1/trunk/tagcoll/TagCollection.h (original)
+++ libtagcoll1/trunk/tagcoll/TagCollection.h Mon Jun 27 17:49:57 2005
@@ -168,28 +168,16 @@
void applyChange(const PatchList<ITEM, TAG>& change) throw ();
// Add an untagged item to the collection
- void add(const ITEM& item) throw ();
+ void consume(const ITEM& item) throw ();
// Add a set of untagged items to the collection
- void add(const OpSet<ITEM>& items) throw ();
+ void consume(const OpSet<ITEM>& items) throw ();
// Add an item with the given tagset to the tagged collection
- void add(const OpSet<TAG>& tagset, const ITEM& item) throw ();
+ void consume(const ITEM& item, const OpSet<TAG>& tagset) throw ();
// Add a set of items with the given tagset to the tagged collection
- void add(const OpSet<TAG>& tagset, const OpSet<ITEM>& items) throw ();
-
- // Add an untagged item to the collection
- void consume(const ITEM& item) throw () { add(item); }
-
- // Add a set of untagged items to the collection
- void consume(const OpSet<ITEM>& items) throw () { add(items); }
-
- // Add an item with the given tagset to the tagged collection
- void consume(const ITEM& item, const OpSet<TAG>& tagset) throw () { add(tagset, item); }
-
- // Add a set of items with the given tagset to the tagged collection
- void consume(const OpSet<ITEM>& items, const OpSet<TAG>& tagset) throw () { add(tagset, items); }
+ void consume(const OpSet<ITEM>& items, const OpSet<TAG>& tagset) throw ();
// Return a tagged collection with all tagsets of this one that contain the
// tag `tag', but with the tag removed
Modified: libtagcoll1/trunk/tagcoll/TagcollBuilder.h
==============================================================================
--- libtagcoll1/trunk/tagcoll/TagcollBuilder.h (original)
+++ libtagcoll1/trunk/tagcoll/TagcollBuilder.h Mon Jun 27 17:49:57 2005
@@ -53,22 +53,22 @@
virtual void consume(const std::string& item) throw ()
{
- coll.add(handleMaker.getHandle(item));
+ coll.consume(handleMaker.getHandle(item));
}
virtual void consume(const std::string& item, const OpSet<std::string>& tags) throw ()
{
- coll.add(tags, handleMaker.getHandle(item));
+ coll.consume(handleMaker.getHandle(item), tags);
}
virtual void consume(const OpSet<std::string>& items) throw ()
{
- coll.add(itemsToHandles(items));
+ coll.consume(itemsToHandles(items));
}
virtual void consume(const OpSet<std::string>& items, const OpSet<std::string>& tags) throw ()
{
- coll.add(tags, itemsToHandles(items));
+ coll.consume(itemsToHandles(items), tags);
}
// Retrieve the resulting collection