[Debtags-commits] [svn] r1558 - in tagcoll/trunk: . tagcoll tests

Enrico Zini enrico at costa.debian.org
Fri Feb 10 09:57:42 UTC 2006


Author: enrico
Date: Fri Feb 10 09:57:40 2006
New Revision: 1558

Added:
   tagcoll/trunk/tagcoll/ReadonlyCollection.h
Modified:
   tagcoll/trunk/   (props changed)
   tagcoll/trunk/tagcoll/Collection.h
   tagcoll/trunk/tagcoll/IntDiskIndex.cc
   tagcoll/trunk/tagcoll/IntDiskIndex.h
   tagcoll/trunk/tagcoll/Makefile.am
   tagcoll/trunk/tagcoll/PatchCollection.h
   tagcoll/trunk/tagcoll/test-utils.cc
   tagcoll/trunk/tests/test-utils.h
Log:
 r7211 at viaza:  enrico | 2006-02-10 10:57:03 +0100
 Split ReadonlyCollection interface out of Collection


Modified: tagcoll/trunk/tagcoll/Collection.h
==============================================================================
--- tagcoll/trunk/tagcoll/Collection.h	(original)
+++ tagcoll/trunk/tagcoll/Collection.h	Fri Feb 10 09:57:40 2006
@@ -23,6 +23,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
 
+#include <tagcoll/ReadonlyCollection.h>
 #include <tagcoll/Consumer.h>
 
 namespace Tagcoll
@@ -37,7 +38,7 @@
  * required to keep track of items with no tags.
  */
 template<typename ITEM, typename TAG>
-class Collection : public Consumer<ITEM, TAG>
+class Collection : public Consumer<ITEM, TAG>, public ReadonlyCollection<ITEM, TAG>
 {
 protected:
 	/*
@@ -50,101 +51,10 @@
 	void consumeItemUntagged(const ITEM&) {}
 	void consumeItemsUntagged(const OpSet<ITEM>&) {}
 
-	/**
-	 * Get the items which are tagged with at least the tag `tag'
-	 *
-	 * \return
-	 *   The items found, or an empty set if no items have that tag
-	 */
-	virtual OpSet<ITEM> getItemsHavingTag(const TAG& tag) const = 0;
-
-	/**
-	 * Get the items which are tagged with at least the tags `tags'
-	 *
-	 * \return
-	 *   The items found, or an empty set if no items have that tag
-	 */
-	virtual OpSet<ITEM> getItemsHavingTags(const OpSet<TAG>& tags) const
-	{
-		if (tags.empty())
-			return OpSet<ITEM>();
-
-		typename OpSet<TAG>::const_iterator i = tags.begin();
-		OpSet<ITEM> res = getItemsHavingTag(*i);
-
-		for ( ; i != tags.end(); i++)
-			res ^= getItemsHavingTag(*i);
-
-		return res;
-
-	}
-
-	/**
-	 * Get the tags attached to an item.
-	 *
-	 * \param item
-	 *   The item to query
-	 * \return 
-	 *   The set of tags, or an empty set if the item has no tags or it does
-	 *   not exist.
-	 */
-	virtual OpSet<TAG> getTagsOfItem(const ITEM& item) const = 0;
-
-	/**
-	 * Get all the tags attached to the items in a set.
-	 *
-	 * \param items
-	 *   The items to query
-	 * \return 
-	 *   The set of tags, or an empty set if the items have no tags or do not
-	 *   exist.
-	 */
-	virtual OpSet<TAG> getTagsOfItems(const OpSet<ITEM>& items) const
-	{
-		OpSet<TAG> res;
-		for (typename OpSet<ITEM>::const_iterator i = items.begin();
-				i != items.end(); i++)
-			res += getTagsOfItem(*i);
-		return res;
-	}
-
 public:
 	virtual ~Collection() {}
 	
 	/**
-	 * Check if the collection contains a tag
-	 *
-	 * \param tag
-	 *   The tag to look for
-	 * \return 
-	 *   true if the collection contains tag, false otherwise
-	 */
-	virtual bool hasTag(const TAG& tag) const
-	{
-		return !getItems(tag).empty();
-	}
-
-	/**
-	 * Get the tags of item `item'.  Return an empty set if `item' does not exist
-	 */
-	OpSet<TAG> getTags(const ITEM& item) const { return getTagsOfItem(item); }
-
-	/**
-	 * Get all the tags of items `items'.  Return an empty set if all of `item' do not exist
-	 */
-	OpSet<TAG> getTags(const OpSet<ITEM>& items) const { return getTagsOfItems(items); }
-
-	/**
-	 * Get the items with tag `tag'.  Return an empty set if `tag' does not exist
-	 */
-	OpSet<ITEM> getItems(const TAG& tag) const { return getItemsHavingTag(tag); }
-
-	/**
-	 * Get the items with tag `tag'.  Return an empty set if `tag' does not exist
-	 */
-	OpSet<ITEM> getItems(const OpSet<TAG>& tags) const { return getItemsHavingTags(tags); }
-
-	/**
 	 * Apply a patch to the collection
 	 *
 	 * Example:
@@ -157,110 +67,6 @@
 	 * \endcode
 	 */
 	virtual void applyChange(const PatchList<ITEM, TAG>& change) = 0;
-
-	/**
-	 * Get the set of all the items that have tags according to this collection
-	 */
-	virtual OpSet<ITEM> getTaggedItems() const = 0;
-
-	/**
-	 * Get the set of all the tags in this collection
-	 */
-	virtual OpSet<TAG> getAllTags() const = 0;
-
-	/**
-	 * Get the cardinality of tag `tag' (that is, the number of items who have it)
-	 */
-	virtual int getCardinality(const TAG& tag) const
-	{
-		return getItemsHavingTag(tag).size();
-	}
-
-	/**
-	 * Get the set of all tags in this collection that appear in tagsets
-	 * containing `tags'
-	 *
-	 * Example:
-	 * \code
-	 * void refineSelection(const OpSet<Tag>& selection)
-	 * {
-	 *    OpSet<Tag> extraTags = collection.getCompanionTags(selection);
-	 *    tagMenu.setAvailableOptions(extraTags);
-	 * }
-	 * \endcode
-	 */
-	virtual OpSet<TAG> getCompanionTags(const OpSet<TAG>& tags) const
-	{
-		return getTagsOfItems(getItemsHavingTags(tags)) - tags;
-	}
-
-	/**
-	 * Get the related items at the given maximum distance
-	 *
-	 * Examples:
-	 * \code
-	 * // Get the items related to a given one, at the given distance
-	 * OpSet<Item> getRelated(const Item& item, int distance)
-	 * {
-	 *    OpSet<Item> res = collection.getRelatedItems(collection.getTags(item), distance);
-	 *    return res - item;
-	 * }
-	 *
-	 * // Get the items related to the given ones, at the given distance
-	 * OpSet<Item> getRelated(const OpSet<Item>& items, int distance)
-	 * {
-	 *    OpSet<Item> res = collection.getRelatedItems(collection.getTags(items), distance);
-	 *    return res - items;
-	 * }
-	 *
-	 * // Get the related items, increasing the distance until it finds at
-	 * // least 'minimum' items
-	 * OpSet<Item> getRelated(const Item& item, int minimum)
-	 * {
-	 *    OpSet<Tag> tags = collection.getTags(item);
-	 *    OpSet<Item> res;
-	 *    for (int i = 0; i < tags.size() && res.size() < minimum; i++)
-	 *    	 res += collection.getRelatedItems(tags, i);
-	 *	  return res - item;
-	 * }
-	 * \endcode
-	 */
-	virtual OpSet<ITEM> getRelatedItems(const OpSet<TAG>& tags, int maxdistance = 1) const
-	{
-		OpSet<ITEM> packages;
-		OpSet<ITEM> res;
-
-		// First get a list of packages that have a non-empty intersection with `tags'
-		for (typename OpSet<TAG>::const_iterator i = tags.begin(); i != tags.end(); i++)
-			packages += getItemsHavingTag(*i);
-
-		// Then keep only those within the given distance
-		for (typename OpSet<ITEM>::const_iterator i = packages.begin(); i != packages.end(); i++)
-		{
-			int dist = tags.distance(getTagsOfItem(*i));
-			if (dist >= 0 && dist <= maxdistance)
-				res += *i;
-		}
-
-		return res;
-	}
-
-	/**
-	 * Output all the contents of the collection to a Consumer
-	 */
-	virtual void output(Consumer<ITEM, TAG>& consumer) const = 0;
-
-	/**
-	 * Send to a consumer all the items which are tagged with at least the
-	 * given tags
-	 */
-	virtual void outputHavingTags(const OpSet<TAG>& tags, Consumer<ITEM, TAG>& consumer) const
-	{
-		OpSet<ITEM> items = getItemsHavingTags(tags);
-		for (typename OpSet<ITEM>::const_iterator i = items.begin();
-				i != items.end(); i++)
-			consumer.consume(*i, getTagsOfItem(*i));
-	}
 };
 
 };

Modified: tagcoll/trunk/tagcoll/IntDiskIndex.cc
==============================================================================
--- tagcoll/trunk/tagcoll/IntDiskIndex.cc	(original)
+++ tagcoll/trunk/tagcoll/IntDiskIndex.cc	Fri Feb 10 09:57:40 2006
@@ -105,20 +105,6 @@
 		}
 }
 
-template<class ITEM, class TAG>
-void IntDiskIndex<ITEM, TAG>::applyChange(const PatchList<ITEM, TAG>& change)
-{
-}
-
-template<class ITEM, class TAG>
-void IntDiskIndex<ITEM, TAG>::consumeItem(const ITEM& item, const OpSet<TAG>& tags)
-{
-}
-
-template<class ITEM, class TAG>
-void IntDiskIndex<ITEM, TAG>::consumeItems(const OpSet<ITEM>& items, const OpSet<TAG>& tags)
-{
-}
 
 
 template<class ITEM, class TAG>

Modified: tagcoll/trunk/tagcoll/IntDiskIndex.h
==============================================================================
--- tagcoll/trunk/tagcoll/IntDiskIndex.h	(original)
+++ tagcoll/trunk/tagcoll/IntDiskIndex.h	Fri Feb 10 09:57:40 2006
@@ -44,7 +44,7 @@
  * TDBDiskIndex to access it afterwards.
  */
 template<class ITEM, class TAG>
-class IntDiskIndex : public Collection<ITEM, TAG>
+class IntDiskIndex : public ReadonlyCollection<ITEM, TAG>
 {
 protected:
 	IntIndex pkgidx;
@@ -54,9 +54,6 @@
 	mutable Converter<int, ITEM>& toitem;
 	mutable Converter<int, TAG>& totag;
 
-	virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags);
-	virtual void consumeItems(const OpSet<ITEM>& items, const OpSet<TAG>& tags);
-
 	virtual OpSet<ITEM> getItemsHavingTag(const TAG& tag) const;
 	virtual OpSet<TAG> getTagsOfItem(const ITEM& item) const;
 
@@ -95,8 +92,6 @@
 	virtual int getCardinality(const TAG& tag) const;
 
 	virtual void output(Consumer<ITEM, TAG>& consumer) const;
-
-	virtual void applyChange(const PatchList<ITEM, TAG>& change);
 };
 
 template<class ITEM, class TAG>

Modified: tagcoll/trunk/tagcoll/Makefile.am
==============================================================================
--- tagcoll/trunk/tagcoll/Makefile.am	(original)
+++ tagcoll/trunk/tagcoll/Makefile.am	Fri Feb 10 09:57:40 2006
@@ -16,6 +16,7 @@
 		\
 		Consumer.h \
 		Filter.h \
+		ReadonlyCollection.h \
 		Collection.h \
 		Patches.h \
 		Patches.cc \

Modified: tagcoll/trunk/tagcoll/PatchCollection.h
==============================================================================
--- tagcoll/trunk/tagcoll/PatchCollection.h	(original)
+++ tagcoll/trunk/tagcoll/PatchCollection.h	Fri Feb 10 09:57:40 2006
@@ -37,7 +37,7 @@
 class PatchCollection : public Collection<ITEM, TAG>
 {
 protected:
-	const Collection<ITEM, TAG>& coll;
+	const ReadonlyCollection<ITEM, TAG>& coll;
 	PatchList<ITEM, TAG> changes;
 
 	virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags);

Modified: tagcoll/trunk/tagcoll/test-utils.cc
==============================================================================
--- tagcoll/trunk/tagcoll/test-utils.cc	(original)
+++ tagcoll/trunk/tagcoll/test-utils.cc	Fri Feb 10 09:57:40 2006
@@ -118,7 +118,7 @@
 	tc.consume("rosmarino", tagset);
 }
 
-void __test_tagged_collection_ro(const Location& loc, Collection<string, string>& tc)
+void __test_tagged_collection_ro(const Location& loc, ReadonlyCollection<string, string>& tc)
 {
 	OpSet<string> s, s1;
 

Modified: tagcoll/trunk/tests/test-utils.h
==============================================================================
--- tagcoll/trunk/tests/test-utils.h	(original)
+++ tagcoll/trunk/tests/test-utils.h	Fri Feb 10 09:57:40 2006
@@ -152,7 +152,7 @@
 
 #define test_tagged_collection_ro(x) (__test_tagged_collection_ro(Location(__FILE__, __LINE__, #x), (x)))
 #define inner_test_tagged_collection_ro(x) (__test_tagged_collection_ro(Location(loc, __FILE__, __LINE__, #x), (x)))
-void __test_tagged_collection_ro(const Location& loc, Collection<string, string>& tc);
+void __test_tagged_collection_ro(const Location& loc, ReadonlyCollection<string, string>& tc);
 
 
 #define test_tagged_collection(x) (__test_tagged_collection(Location(__FILE__, __LINE__, #x), (x)))



More information about the Debtags-commits mailing list