From 47fb95d6086c2c67086316a25b4c0858783d3c2b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 11:29:31 +0000 Subject: Added PathTable, simple pretty wrapper around Table which provides super fast "find all descendants". I couldn't deal with the 'one big table' or 'parents own/lookup children' decision, so I came up with this thing instead. It's pretty cool I guess. git-svn-id: http://svn.drobilla.net/lad/raul@635 a436a847-0d15-0410-975c-d299462d15a1 --- tests/table_test.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/table_test.cpp b/tests/table_test.cpp index 3ed3c7e..35bc408 100644 --- a/tests/table_test.cpp +++ b/tests/table_test.cpp @@ -1,15 +1,30 @@ #include #include #include +#include #include #include using namespace Raul; using namespace std; +int range_end_val; + +bool range_comparator(const int& a, const int& b) +{ + bool ret = (b >= a && b <= range_end_val); + //cout << "COMP: " << a << " . " << b << " = " << ret << endl; + return ret; +} + + int main() { + srand(time(NULL)); + + range_end_val = rand()%10; + Table t; for (size_t i=0; i < 20; ++i) { int val = rand()%10; @@ -18,10 +33,22 @@ main() t[20] = 20; t[21] = 21; - + + cout << "Contents:" << endl; for (Table::const_iterator i = t.begin(); i != t.end(); ++i) cout << i->first << " "; cout << endl; + + std::cout << "Range " << t.begin()->first << " .. " << range_end_val << std::endl; + + Table::const_iterator range_begin = t.begin(); + ++range_begin; ++range_begin; + + Table::const_iterator range_end = t.find_range_end(t.begin(), range_comparator); + + for (Table::const_iterator i = t.begin(); i != range_end; ++i) + cout << i->first << " "; + cout << endl; Table::iterator first = t.begin(); ++first; @@ -66,9 +93,40 @@ main() /* **** */ - cout << "Assuming you built with debugging, if this continues to run " + PathTable pt; + pt.insert(make_pair("/foo", 'a')); + pt.insert(make_pair("/bar", 'a')); + pt.insert(make_pair("/bar/baz", 'b')); + pt.insert(make_pair("/bar/bazz/NO", 'c')); + pt.insert(make_pair("/bar/baz/YEEEAH", 'c')); + pt.insert(make_pair("/bar/baz/YEEEAH/BOOOEEEEE", 'c')); + pt.insert(make_pair("/bar/buzz", 'b')); + pt.insert(make_pair("/bar/buzz/WHAT", 'c')); + pt.insert(make_pair("/bar/buzz/WHHHhhhhhAT", 'c')); + pt.insert(make_pair("/quux", 'a')); + + cout << "Paths: " << endl; + for (PathTable::const_iterator i = pt.begin(); i != pt.end(); ++i) + cout << i->first << " "; + cout << endl; + + PathTable::const_iterator descendants_begin = pt.begin(); + size_t begin_index = rand() % pt.size(); + for (size_t i=0; i < begin_index; ++i) + ++descendants_begin; + + cout << "\nDescendants of " << descendants_begin->first << endl; + PathTable::const_iterator descendants_end = pt.find_descendants_end(descendants_begin); + + for (PathTable::const_iterator i = pt.begin(); i != descendants_end; ++i) + cout << i->first << " "; + cout << endl; + + /* **** */ + + cout << "\nAssuming you built with debugging, if this continues to run " << "and chews your CPU without dying, everything's good." << endl; - srand(time(NULL)); + Table st; -- cgit v1.2.1