[Debtags-commits] [svn] r1885 - in tagcoll/2.0: . tagcoll tagcoll/coll tools

Enrico Zini enrico at costa.debian.org
Thu Aug 31 16:12:54 UTC 2006


Author: enrico
Date: Thu Aug 31 16:12:53 2006
New Revision: 1885

Added:
   tagcoll/2.0/tools/Timing.h
Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/Makefile.am
   tagcoll/2.0/tagcoll/coll/base.h
   tagcoll/2.0/tagcoll/coll/fast.h
   tagcoll/2.0/tagcoll/coll/fast.tcc
   tagcoll/2.0/tools/Makefile.am
   tagcoll/2.0/tools/TagcollParser.h
   tagcoll/2.0/tools/tagcoll.cc
Log:
 r3229 at viaza:  enrico | 2006-08-31 18:12:22 +0200
 Properly build with new wibble
 Made tagcoll reverse smarter
 Added "tagcoll test" command to do some tests and timings (aka, for Enrico to play with)
 Added more efficient outputReversed method to coll::Fast


Modified: tagcoll/2.0/tagcoll/Makefile.am
==============================================================================
--- tagcoll/2.0/tagcoll/Makefile.am	(original)
+++ tagcoll/2.0/tagcoll/Makefile.am	Thu Aug 31 16:12:53 2006
@@ -112,7 +112,7 @@
 		tests/tut-main.cpp
 # Disabled: it failed, but it also looks meaningless as it is
 # test-textformat.cc
-tests_libtagcoll_test_LDADD = -dlpreopen libtagcoll.la tagexpr/libtagexpr.la -lz
+tests_libtagcoll_test_LDADD = libtagcoll.la tagexpr/libtagexpr.la @LIBWIBBLE_LIBS@ -lz
 
 #noinst_PROGRAMS = normalize mkgraph
 # test-tagset

Modified: tagcoll/2.0/tagcoll/coll/base.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/base.h	(original)
+++ tagcoll/2.0/tagcoll/coll/base.h	Thu Aug 31 16:12:53 2006
@@ -221,7 +221,7 @@
 	typename coll_traits<Self>::itemset_type getRelatedItems(const TAGS& tags, int maxdistance = 1) const;
 
 	/**
-	 * Output all the contents of the collection to a Consumer
+	 * Output all the contents of the collection to an output iterator
 	 */
 	template<typename OUT>
 	void output(OUT out) const;

Modified: tagcoll/2.0/tagcoll/coll/fast.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.h	(original)
+++ tagcoll/2.0/tagcoll/coll/fast.h	Thu Aug 31 16:12:53 2006
@@ -82,6 +82,10 @@
 	template<typename ITEMS, typename TAGS>
 	void insert(const ITEMS& items, const TAGS& tags);
 
+	void insert(const wibble::Singleton<ITEM>& item, const std::set<TAG>& tags);
+
+	void insert(const std::set<ITEM>& items, const wibble::Singleton<TAG>& tag);
+
 	void clear() { items.clear(); tags.clear(); }
 
 	std::set<TAG> getTagsOfItem(const ITEM& item) const;
@@ -98,6 +102,12 @@
 	unsigned int itemCount() const { return items.size(); }
 	unsigned int tagCount() const { return tags.size(); }
 
+	/**
+	 * Output all the contents of the reversed collection to an output iterator
+	 */
+	template<typename OUT>
+	void outputReversed(OUT out) const;
+
 #if 0
 	void output(Consumer<ITEM, TAG>& consumer) const;
 #endif

Modified: tagcoll/2.0/tagcoll/coll/fast.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.tcc	(original)
+++ tagcoll/2.0/tagcoll/coll/fast.tcc	Thu Aug 31 16:12:53 2006
@@ -63,6 +63,53 @@
 }
 
 template<class ITEM, class TAG>
+void Fast<ITEM, TAG>::insert(const wibble::Singleton<ITEM>& item, const std::set<TAG>& tags)
+{
+	using namespace wibble::operators;
+
+	if (tags.empty())
+		return;
+
+	typename std::map< ITEM, std::set<TAG> >::iterator iter = this->items.find(*item.begin());
+	if (iter == this->items.end())
+		this->items.insert(std::make_pair(*item.begin(), tags));
+	else
+		iter->second |= tags;
+
+	for (typename std::set<TAG>::const_iterator i = tags.begin();
+			i != tags.end(); ++i)
+	{
+		typename std::map< TAG, std::set<ITEM> >::iterator iter = this->tags.find(*i);
+		if (iter == this->tags.end())
+			this->tags.insert(std::make_pair(*i, std::set<ITEM>() | *item.begin()));
+		else
+			iter->second |= *item.begin();
+	}
+}
+
+template<class ITEM, class TAG>
+void Fast<ITEM, TAG>::insert(const std::set<ITEM>& items, const wibble::Singleton<TAG>& tag)
+{
+	using namespace wibble::operators;
+
+	for (typename std::set<ITEM>::const_iterator i = items.begin();
+			i != items.end(); ++i)
+	{
+		typename std::map< ITEM, std::set<TAG> >::iterator iter = this->items.find(*i);
+		if (iter == this->items.end())
+			this->items.insert(std::make_pair(*i, std::set<TAG>() | *tag.begin()));
+		else
+			iter->second |= *tag.begin();
+	}
+
+	typename std::map< TAG, std::set<ITEM> >::iterator iter = this->tags.find(*tag.begin());
+	if (iter == this->tags.end())
+		this->tags.insert(std::make_pair(*tag.begin(), items));
+	else
+		iter->second |= items;
+}
+
+template<class ITEM, class TAG>
 std::set<ITEM> Fast<ITEM, TAG>::getItemsHavingTag(const TAG& tag) const
 {
 	typename map<TAG, std::set<ITEM> >::const_iterator i = tags.find(tag);
@@ -122,6 +169,18 @@
 }
 #endif
 
+template<class ITEM, class TAG> template<typename OUT>
+void Fast<ITEM, TAG>::outputReversed(OUT out) const
+{
+	for (typename std::map<TAG, std::set<ITEM> >::const_iterator i = tags.begin();
+			i != tags.end(); ++i)
+	{
+		*out = make_pair(wibble::singleton(i->first), i->second);
+		++out;
+	}
+}
+
+
 template<class ITEM, class TAG>
 void Fast<ITEM, TAG>::applyChange(const PatchList<ITEM, TAG>& change)
 {

Modified: tagcoll/2.0/tools/Makefile.am
==============================================================================
--- tagcoll/2.0/tools/Makefile.am	(original)
+++ tagcoll/2.0/tools/Makefile.am	Thu Aug 31 16:12:53 2006
@@ -7,14 +7,14 @@
 noinst_PROGRAMS = manpage
 
 tagcoll_SOURCES = tagcoll.cc
-tagcoll_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
+tagcoll_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la @LIBWIBBLE_LIBS@
 
 #tagidx_SOURCES = BasicStringDiskIndex.cc tagidx.cc
 #tagidx_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
 
 manpage_SOURCES = manpage.cc
-manpage_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
+manpage_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la @LIBWIBBLE_LIBS@
 
 INCLUDES = -I$(top_srcdir)
 
-EXTRA_DIST = CommandlineParser.h TagcollParser.h TagidxParser.h
+EXTRA_DIST = CommandlineParser.h TagcollParser.h TagidxParser.h Timing.h

Modified: tagcoll/2.0/tools/TagcollParser.h
==============================================================================
--- tagcoll/2.0/tools/TagcollParser.h	(original)
+++ tagcoll/2.0/tools/TagcollParser.h	Thu Aug 31 16:12:53 2006
@@ -63,6 +63,7 @@
 	Engine* cleanhierarchy;
 	Engine* findspecials;
 	Engine* grep;
+	Engine* test;
 
 protected:
 	// Create the input options group
@@ -236,6 +237,11 @@
 				"invert the sense of matching, to select non-matching lines");
 		misc_quiet = grep->add<BoolOption>("quiet", 'q', "quiet", "",
 				"do not write anything to standard output, but exit with 0 if any match is found");
+
+		// 'test' group
+		test = addEngine("test", "[files...]",
+			"perform internal tests and timings");
+		test->add(inputOpts);
 	}
 };
 

Modified: tagcoll/2.0/tools/tagcoll.cc
==============================================================================
--- tagcoll/2.0/tools/tagcoll.cc	(original)
+++ tagcoll/2.0/tools/tagcoll.cc	Thu Aug 31 16:12:53 2006
@@ -61,6 +61,7 @@
 #include <sstream>
 
 #include "TagcollParser.h"
+#include "Timing.h"
 
 using namespace std;
 using namespace tagcoll;
@@ -736,9 +737,9 @@
 			if (opts.misc_untaggedTag->boolValue())
 				revnull = opts.misc_untaggedTag->stringValue();
 
-			coll::Simple<string, string> reversed;
-			tagcoll.readAll(stream::reverser(revnull, inserter(reversed)));
-			reversed.output(tagcoll.writer());
+			coll::Fast<string, string> coll;
+			tagcoll.readAll(inserter(coll));
+			coll.outputReversed(tagcoll.writer());
 		}
 		else if (opts.foundCommand() == opts.copy)
 		{
@@ -797,6 +798,23 @@
 		{
 			return tagcoll.grep(opts.next());
 		}
+		else if (opts.foundCommand() == opts.test)
+		{
+			Timing timing("test");
+
+			coll::Fast<string, string> coll;
+			tagcoll.readAll(inserter(coll));
+
+			cerr << timing.partial() << ": read collection." << endl;
+
+			{
+				coll::Simple<string, string> t;
+				coll.outputReversed(inserter(t));
+			}
+			cerr << timing.partial() << ": reversed." << endl;
+
+			cerr << timing.total() << ": total." << endl;
+		}
 		else
 			throw wibble::exception::BadOption(string("unhandled command ") +
 						(opts.foundCommand() ? opts.foundCommand()->name() : "(null)"));



More information about the Debtags-commits mailing list