summaryrefslogtreecommitdiff
path: root/src/tests/ordhash.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-11-27 10:13:44 +0000
committerMike Buland <eichlan@xagasoft.com>2006-11-27 10:13:44 +0000
commit3025ed54309f793c6afbcbc9a564f71cc741f2ef (patch)
treeb579210f2f894bfeb7562e3339aea58c377c26b7 /src/tests/ordhash.cpp
parentdd049c4b3bbe6a605e41b043d933c02cb8497968 (diff)
downloadlibbu++-3025ed54309f793c6afbcbc9a564f71cc741f2ef.tar.gz
libbu++-3025ed54309f793c6afbcbc9a564f71cc741f2ef.tar.bz2
libbu++-3025ed54309f793c6afbcbc9a564f71cc741f2ef.tar.xz
libbu++-3025ed54309f793c6afbcbc9a564f71cc741f2ef.zip
Added the new OrdHash, check the test file for an example.
Diffstat (limited to 'src/tests/ordhash.cpp')
-rw-r--r--src/tests/ordhash.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tests/ordhash.cpp b/src/tests/ordhash.cpp
new file mode 100644
index 0000000..f1d96ec
--- /dev/null
+++ b/src/tests/ordhash.cpp
@@ -0,0 +1,48 @@
1#include "ordhash.h"
2#include <string>
3
4typedef struct eldef
5{
6 eldef( int a, int b, const std::string &c ) :
7 id( a ), nSequence( b ), sName( c ) {}
8 int id;
9 int nSequence;
10 std::string sName;
11} eldef;
12
13struct seqcmp
14{
15 bool operator()( eldef **a, eldef **b )
16 {
17 return (*a)->nSequence < (*b)->nSequence;
18 }
19};
20
21struct namcmp
22{
23 bool operator()( eldef **a, eldef **b )
24 {
25 return (*a)->sName < (*b)->sName;
26 }
27};
28
29typedef OrdHash<int, eldef, seqcmp> AHash;
30//typedef OrdHash<int, eldef, namcmp> AHash;
31
32int main()
33{
34 AHash hsh;
35 hsh[1] = eldef( 0, 43, "Bob");
36 hsh[4] = eldef( 1, 443, "Abby");
37 hsh[2] = eldef( 2, 1, "Name");
38 hsh[5] = eldef( 3, 0, "Catagory");
39 hsh[32] = eldef( 4, 12, "Epilogue");
40
41 for( AHash::iterator i = hsh.begin(); i != hsh.end(); i++ )
42 {
43 eldef e = (*i).second;
44 printf("%d, %d, %s\n", e.id, e.nSequence, e.sName.c_str() );
45 }
46
47}
48