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

Enrico Zini enrico at costa.debian.org
Thu May 11 00:30:42 UTC 2006


Author: enrico
Date: Thu May 11 00:30:40 2006
New Revision: 1754

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/coll/fast.cc
   tagcoll/2.0/tagcoll/coll/fast.h
   tagcoll/2.0/tools/tagcoll.cc
Log:
 r2689 at viaza:  enrico | 2006-05-10 13:04:17 -0500
 Added removeTagsWithCardinalityLessThan method to coll::Fast


Modified: tagcoll/2.0/tagcoll/coll/fast.cc
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.cc	(original)
+++ tagcoll/2.0/tagcoll/coll/fast.cc	Thu May 11 00:30:40 2006
@@ -129,6 +129,25 @@
 	ensure_equals(tag, "tomato");
 }
 
+template<> template<>
+void to::test<7>()
+{
+	std::string target(
+			"margherita: tomato\n"
+			"funghi: tomato\n"
+			"marinara: tomato\n"
+			);
+	Simple<string, string> result;
+
+	Fast<string, string> coll;
+	output_test_collection(inserter(coll));
+
+	coll.removeTagsWithCardinalityLessThan(3);
+
+	parseCollection(target, inserter(result));
+	ensure_coll_equals(result, coll);
+}
+
 }
 }
 

Modified: tagcoll/2.0/tagcoll/coll/fast.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.h	(original)
+++ tagcoll/2.0/tagcoll/coll/fast.h	Thu May 11 00:30:40 2006
@@ -155,6 +155,21 @@
 	Fast<ITEM, TAG> getChildCollection(const TAG& tag) const;
 
 	void removeTag(const TAG& tag);
+
+	void removeTagsWithCardinalityLessThan(size_t card)
+	{
+		typename std::map<TAG, std::set<ITEM> >::const_iterator i = tags.begin();
+		while (i != tags.end())
+		{
+			if (i->second.size() < card)
+			{
+				typename std::map<TAG, std::set<ITEM> >::const_iterator j = i;
+				++i;
+				removeTag(j->first);
+			} else
+				++i;
+		}
+	}
 };
 
 }

Modified: tagcoll/2.0/tools/tagcoll.cc
==============================================================================
--- tagcoll/2.0/tools/tagcoll.cc	(original)
+++ tagcoll/2.0/tools/tagcoll.cc	Thu May 11 00:30:40 2006
@@ -45,10 +45,8 @@
 #include <tagcoll/stream/patcher.h>
 #include <tagcoll/stream/expression.h>
 
-#include <tagcoll/CardinalityStore.h>
 #include <tagcoll/SmartHierarchy.h>
 
-#include <tagcoll/Consumer.h>
 #include <tagcoll/coll/simple.h>
 #include <tagcoll/Implications.h>
 #include <tagcoll/Patches.h>
@@ -57,7 +55,6 @@
 
 #include <tagcoll/input/stdio.h>
 #include <tagcoll/TextFormat.h>
-#include <tagcoll/Serializer.h>
 
 #include <algorithm>
 #include <iostream>
@@ -84,7 +81,8 @@
 		cout << prefix << *i << endl;
 }
 
-void printNode(HierarchyNode<string, string>* node, string prefix = "")
+template<typename COLL>
+void printNode(HierarchyNode<COLL>* node, string prefix = "")
 {
 	std::set<string> items = node->getItems();
 	if (!items.empty())
@@ -97,18 +95,19 @@
 	if (prefix.size() > 0 && prefix[prefix.size() - 1] != '/')
 		prefix += '/';
 
-	for (HierarchyNode<string, string>::iterator i = node->begin();
+	for (typename HierarchyNode<COLL>::iterator i = node->begin();
 			i != node->end(); i++)
 	{
 		printNode(*i, prefix + (*i)->tag());
 	}
 }
 
-std::set<string> getItems(HierarchyNode<string, string>* node)
+template<typename COLL>
+std::set<string> getItems(HierarchyNode<COLL>* node)
 {
 	std::set<string> items = node->getItems();
 	
-	for (HierarchyNode<string, string>::iterator i = node->begin();
+	for (typename HierarchyNode<COLL>::iterator i = node->begin();
 			i != node->end(); i++)
 		items |= getItems(*i);
 
@@ -133,12 +132,10 @@
 
 PatchList<string, string> readPatches(const string& file)
 {
-	TrivialConverter<string, string> conv;
-
 	if (file == "-")
 	{
 		input::Stdio input(stdin, "<stdin>");
-		return textformat::parsePatch(conv, conv, input);
+		return textformat::parsePatch(input);
 	}
 	else if (isdir(file))
 	{
@@ -151,7 +148,7 @@
 			if (d->d_name[0] == '.')
 				continue;
 			input::Stdio input(file + '/' + d->d_name);
-			patches.addPatch(textformat::parsePatch(conv, conv, input));
+			patches.addPatch(textformat::parsePatch(input));
 		}
 		closedir(dir);
 		return patches;
@@ -159,7 +156,7 @@
 	else
 	{
 		input::Stdio input(file);
-		return textformat::parsePatch(conv, conv, input);
+		return textformat::parsePatch(input);
 	}
 }
 
@@ -440,6 +437,23 @@
 								removeDerived(derivedTags,
 									removeImplied(implications,
 										FilterForwarder(out)))));
+		else
+			if (derivedTags.empty())
+				if (implications.empty())
+					return out;
+				else
+					return filterStep(addImplied(implications, FilterForwarder(out)));
+			else
+				if (implications.empty())
+					return filterStep(addDerived(derivedTags, FilterForwarder(out)));
+				else
+					// Expand implications, then add derived tags computing
+					// them using the expanded tag set
+					return filterStep(
+							addImplied(implications,
+								addDerived(derivedTags,
+									addImplied(implications,
+										FilterForwarder(out)))));
 	}
 
 	FilterStep* makeWriterTail()
@@ -527,8 +541,7 @@
 		PatchList<string, string> newpatches;
 		newpatches.addPatch(merger1, merger2);
 
-		TrivialConverter<string, string> conv;
-		TextFormat<string, string>::outputPatch(conv, conv, newpatches, stdout);
+		textformat::outputPatch(newpatches, stdout);
 	}
 
 	void copy()
@@ -538,18 +551,18 @@
 
 	int grep(const std::string& expr)
 	{
-		int count = 0;
+		int countItems = 0, countTags = 0;
 		stream::ExpressionFilter::MatchType type =
 			opts.misc_invert->boolValue() ?
 			stream::ExpressionFilter::INVERTED : stream::ExpressionFilter::PLAIN;
 
 		if (opts.misc_quiet->boolValue())
-			readAll(stream::filterItemsByExpression(expr, type, stream::countingSink(count)));
+			readAll(stream::filterItemsByExpression(expr, type, stream::countingSink(countItems, countTags)));
 		else
 			readAll(stream::filterItemsByExpression(expr, type,
-						teeFilter(writer(), stream::countingSink(count))));
+						teeFilter(writer(), stream::countingSink(countItems, countTags))));
 
-		return count > 0 ? 0 : 1;
+		return countItems > 0 ? 0 : 1;
 	}
 };
 
@@ -567,8 +580,8 @@
 		// Perform the correct operation
 		if (opts.foundCommand() == opts.implications)
 		{
-			CardinalityStore<string, string> coll;
-			tagcoll.readAll(consumer(coll));
+			coll::Fast<string, string> coll;
+			tagcoll.readAll(inserter(coll));
 
 			Implications<string> newImpls;
 
@@ -579,17 +592,15 @@
 			{
 				std::set<string> implied = coll.getImpliedBy(*t);
 				if (!implied.empty())
-					newImpls.consume(*t, implied);
+					newImpls.insert(wibble::singleton(*t), implied);
 			}
 
 			newImpls.pack();
 
-			TrivialConverter<string, string> conv;
-			TextFormat<string, string> output(conv, conv, stdout);
 			if (opts.out_redundant->boolValue())
-				newImpls.outputFull(output);
+				newImpls.outputFull(textformat::StdioWriter(stdout));
 			else
-				newImpls.output(output);
+				newImpls.output(textformat::StdioWriter(stdout));
 		}
 		else if (opts.foundCommand() == opts.hierarchy)
 		{
@@ -597,15 +608,15 @@
 			if (opts.hie_flatten->boolValue())
 				flattenThreshold = opts.hie_flatten->intValue();
 
-			CardinalityStore<string, string> coll;
-			tagcoll.readAll(consumer(coll));
+			coll::Fast<string, string> coll;
+			tagcoll.readAll(inserter(coll));
 
 			if (opts.hie_filter->boolValue())
 				coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
 
 			// Default operation: build the smart hierarchy
-			HierarchyNode<string, string>* root =
-				new SmartHierarchyNode<string, string>("_top", coll, flattenThreshold);
+			HierarchyNode< coll::Fast<string, string> >* root =
+				smartHierarchyNode("_top", coll, flattenThreshold);
 			printNode(root, "/");
 		}
 		else if (opts.foundCommand() == opts.cleanhierarchy)
@@ -614,14 +625,15 @@
 			if (opts.hie_flatten->boolValue())
 				flattenThreshold = opts.hie_flatten->intValue();
 
-			CardinalityStore<string, string> coll;
-			tagcoll.readAll(consumer(coll));
+			coll::Fast<string, string> coll;
+			tagcoll.readAll(inserter(coll));
 
 			if (opts.hie_filter->boolValue())
 				coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
 
 			// Default operation: build the smart hierarchy
-			HierarchyNode<string, string>* root = new CleanSmartHierarchyNode<string, string>("_top", coll, flattenThreshold);
+			HierarchyNode< coll::Fast<string, string> >* root =
+				cleanSmartHierarchyNode("_top", coll, flattenThreshold);
 			printNode(root, "/");
 		}
 		else if (opts.foundCommand() == opts.diff)
@@ -632,7 +644,7 @@
 		{
 			string item = opts.next();
 			coll::Simple<string, string> merger;
-			tagcoll.readAll(merger);
+			tagcoll.readAll(inserter(merger));
 
 			int maxdist = 0;
 			if (opts.misc_distance->boolValue())
@@ -677,8 +689,8 @@
 			}
 
 			// Build a full TagCollection
-			CardinalityStore<string, string> coll;
-			merger.output(coll);
+			coll::Fast<string, string> coll;
+			merger.output(inserter(coll));
 
 			printItems(coll.getItemsExactMatch(ts));
 
@@ -713,17 +725,17 @@
 			if (opts.hie_flatten->boolValue())
 				flattenThreshold = opts.hie_flatten->intValue();
 
-			CardinalityStore<string, string> coll;
-			tagcoll.readAll(consumer(coll));
+			coll::Fast<string, string> coll;
+			tagcoll.readAll(inserter(coll));
 
 			if (opts.hie_filter->boolValue())
 				coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
 
 			// Default operation: build the smart hierarchy
-			SmartHierarchyNode<string, string> root("_top", coll, flattenThreshold);
+			SmartHierarchyNode< coll::Fast<string, string> > root("_top", coll, flattenThreshold);
 
 			std::set<string> seen;
-			for (HierarchyNode<string, string>::iterator i = root.begin();
+			for (HierarchyNode< coll::Fast<string, string> >::iterator i = root.begin();
 					i != root.end(); i++)
 			{
 				std::set<string> items = getItems(*i);



More information about the Debtags-commits mailing list