aboutsummaryrefslogtreecommitdiff
path: root/src/old/tests/ordhash.cpp
blob: f1d96ecbe4e901817cbe547dfa049e9b13595e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "ordhash.h"
#include <string>

typedef struct eldef
{
	eldef( int a, int b, const std::string &c ) :
		id( a ), nSequence( b ), sName( c ) {}
	int id;
	int nSequence;
	std::string sName;
} eldef;

struct seqcmp
{
	bool operator()( eldef **a,  eldef **b )
	{
		return (*a)->nSequence < (*b)->nSequence;
	}
};

struct namcmp
{
	bool operator()( eldef **a,  eldef **b )
	{
		return (*a)->sName < (*b)->sName;
	}
};

typedef OrdHash<int, eldef, seqcmp> AHash;
//typedef OrdHash<int, eldef, namcmp> AHash;

int main()
{
	AHash hsh;
	hsh[1] = eldef( 0, 43, "Bob");
	hsh[4] = eldef( 1, 443, "Abby");
	hsh[2] = eldef( 2, 1, "Name");
	hsh[5] = eldef( 3, 0, "Catagory");
	hsh[32] = eldef( 4, 12, "Epilogue");

	for( AHash::iterator i = hsh.begin(); i != hsh.end(); i++ )
	{
		eldef e = (*i).second;
		printf("%d, %d, %s\n", e.id, e.nSequence, e.sName.c_str() );
	}

}