summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-07-26 11:29:31 +0000
committerDavid Robillard <d@drobilla.net>2007-07-26 11:29:31 +0000
commit47fb95d6086c2c67086316a25b4c0858783d3c2b (patch)
tree4ac9934f1f38b0b6ed42f41b2bd9d7cdbc90c2f8 /tests
parent25b9a123b60f769506a829542d05f38b1e95d51b (diff)
downloadraul-47fb95d6086c2c67086316a25b4c0858783d3c2b.tar.gz
raul-47fb95d6086c2c67086316a25b4c0858783d3c2b.tar.bz2
raul-47fb95d6086c2c67086316a25b4c0858783d3c2b.zip
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
Diffstat (limited to 'tests')
-rw-r--r--tests/table_test.cpp64
1 files changed, 61 insertions, 3 deletions
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 <string>
#include <iostream>
#include <utility>
+#include <raul/PathTable.hpp>
#include <raul/Table.hpp>
#include <raul/TableImpl.hpp>
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<int, int> 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<int,int>::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<int,int>::const_iterator range_begin = t.begin();
+ ++range_begin; ++range_begin;
+
+ Table<int,int>::const_iterator range_end = t.find_range_end(t.begin(), range_comparator);
+
+ for (Table<int,int>::const_iterator i = t.begin(); i != range_end; ++i)
+ cout << i->first << " ";
+ cout << endl;
Table<int, int>::iterator first = t.begin();
++first;
@@ -66,9 +93,40 @@ main()
/* **** */
- cout << "Assuming you built with debugging, if this continues to run "
+ PathTable<char> 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<char>::const_iterator i = pt.begin(); i != pt.end(); ++i)
+ cout << i->first << " ";
+ cout << endl;
+
+ PathTable<char>::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<char>::const_iterator descendants_end = pt.find_descendants_end(descendants_begin);
+
+ for (PathTable<char>::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<string, string> st;