[Debtags-commits] [svn] r1848 - in tagcoll/2.0: . tagcoll
tagcoll/coll
Enrico Zini
enrico at costa.debian.org
Tue Aug 15 16:42:44 UTC 2006
Author: enrico
Date: Tue Aug 15 16:42:40 2006
New Revision: 1848
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/SmartHierarchy-tut.cc
tagcoll/2.0/tagcoll/SmartHierarchy.h
tagcoll/2.0/tagcoll/SmartHierarchy.tcc
tagcoll/2.0/tagcoll/coll/fast.h
Log:
r3167 at viaza: enrico | 2006-08-15 17:42:31 +0100
Added SmartCollection tests for when items != tags (to replicate a compiler error found in debtags-edit)
Fixed coll_traits for fast (itemset and tagsets were reversed: ARGH!)
Generalised the tag merging in CleanSmartHierarchyNode
Modified: tagcoll/2.0/tagcoll/SmartHierarchy-tut.cc
==============================================================================
--- tagcoll/2.0/tagcoll/SmartHierarchy-tut.cc (original)
+++ tagcoll/2.0/tagcoll/SmartHierarchy-tut.cc Tue Aug 15 16:42:40 2006
@@ -56,6 +56,28 @@
//ensure(false);
}
+std::set<int> ints(int i1, int i2, int i3)
+{
+ std::set<int> res;
+ res.insert(i1); res.insert(i2); res.insert(i3);
+ return res;
+}
+
+// Try out with a collection where the item is a different type than the tag
+template<> template<>
+void to::test<2>()
+{
+ coll::Fast<string, int> coll;
+ coll.insert(wibble::singleton(std::string("even")), ints(0, 2, 4));
+ coll.insert(wibble::singleton(std::string("odd")), ints(0, 1, 3));
+
+ HierarchyNode< coll::Fast<string, int> >* root = smartHierarchyNode(0, coll, 2);
+ delete root;
+
+ root = cleanSmartHierarchyNode(0, coll, 2);
+ delete root;
+}
+
}
}
Modified: tagcoll/2.0/tagcoll/SmartHierarchy.h
==============================================================================
--- tagcoll/2.0/tagcoll/SmartHierarchy.h (original)
+++ tagcoll/2.0/tagcoll/SmartHierarchy.h Tue Aug 15 16:42:40 2006
@@ -44,7 +44,7 @@
TAG _tag;
COLL* coll;
std::vector<HierarchyNode<COLL>*> children;
- std::set<ITEM> items;
+ ITEMSET items;
HierarchyNode<COLL>* _parent;
public:
@@ -118,7 +118,7 @@
typedef typename HierarchyNode<COLL>::ITEMSET ITEMSET;
typedef typename HierarchyNode<COLL>::TAGSET TAGSET;
- std::set<ITEM> unexpandedItems;
+ typename HierarchyNode<COLL>::ITEMSET unexpandedItems;
// Threshold of child items below which the child hierarchy is flattened
// and they all become children of this node
@@ -160,6 +160,18 @@
return new SmartHierarchyNode<COLL>(parent, tag, coll, flattenThreshold);
}
+template<typename TAG>
+TAG mergeTags(const TAG& tag1, const TAG& tag2)
+{
+ return tag1;
+}
+
+template<>
+std::string mergeTags(const std::string& tag1, const std::string& tag2)
+{
+ return tag1 + ", " + tag2;
+}
+
// SmartHierarchyNode which also does merging of equivalent tags
template<typename COLL>
Modified: tagcoll/2.0/tagcoll/SmartHierarchy.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/SmartHierarchy.tcc (original)
+++ tagcoll/2.0/tagcoll/SmartHierarchy.tcc Tue Aug 15 16:42:40 2006
@@ -36,7 +36,8 @@
using namespace std;
using namespace wibble::operators;
-using namespace tagcoll;
+
+namespace tagcoll {
//template class SmartHierarchyNode<string>;
//template class SmartHierarchyNode<int>;
@@ -185,17 +186,14 @@
// If we contain only one child node, replace it with his expansion
while (this->children.size() == 1 && this->items.empty())
{
- CleanSmartHierarchyNode* child = static_cast<CleanSmartHierarchyNode*>(this->children[0]);
+ CleanSmartHierarchyNode<COLL>* child = static_cast<CleanSmartHierarchyNode<COLL>*>(this->children[0]);
this->children.clear();
// Move the child's children to this node
for (typename CleanSmartHierarchyNode::iterator i = child->begin();
i != child->end(); i++)
{
- // TODO: make a mergeTags method which in the general case keeps
- // the first tag, and in the string case it joins the tags with a
- // comma
- static_cast<CleanSmartHierarchyNode*>(*i)->setTag(child->tag() + ", " + (*i)->tag());
+ static_cast<CleanSmartHierarchyNode*>(*i)->setTag(mergeTags(child->tag(), (*i)->tag()));
static_cast<CleanSmartHierarchyNode*>(*i)->setParent(this);
this->children.push_back(*i);
}
@@ -210,5 +208,6 @@
this->coll = 0;
}
+}
// vim:set ts=4 sw=4:
Modified: tagcoll/2.0/tagcoll/coll/fast.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/fast.h (original)
+++ tagcoll/2.0/tagcoll/coll/fast.h Tue Aug 15 16:42:40 2006
@@ -39,8 +39,8 @@
{
typedef ITEM item_type;
typedef TAG tag_type;
- typedef std::set<ITEM> tagset_type;
- typedef std::set<TAG> itemset_type;
+ typedef std::set<ITEM> itemset_type;
+ typedef std::set<TAG> tagset_type;
};
/**
More information about the Debtags-commits
mailing list