diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-07-26 21:58:35 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-07-26 21:58:35 +0000 |
commit | 76ed3c164662f4ee4c109bb2054c61c99ea86251 (patch) | |
tree | 301d4687f95a457304b0e796984b62fa89992718 /src/hash.h | |
parent | 579c3ac445043122b0a702bdb2542d9ea404b62e (diff) | |
download | libbu++-76ed3c164662f4ee4c109bb2054c61c99ea86251.tar.gz libbu++-76ed3c164662f4ee4c109bb2054c61c99ea86251.tar.bz2 libbu++-76ed3c164662f4ee4c109bb2054c61c99ea86251.tar.xz libbu++-76ed3c164662f4ee4c109bb2054c61c99ea86251.zip |
Added the not-yet-working hash class. More thought must be done. This doesn't
actually change any existing code really just adds a new class that you can't
use because it's commented out. I'll probably move it to a branch.
Diffstat (limited to 'src/hash.h')
-rw-r--r-- | src/hash.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/hash.h b/src/hash.h new file mode 100644 index 0000000..8385bb9 --- /dev/null +++ b/src/hash.h | |||
@@ -0,0 +1,106 @@ | |||
1 | #ifndef HASH_H | ||
2 | #define HASH_H | ||
3 | /* | ||
4 | #include <stddef.h> | ||
5 | #include <string.h> | ||
6 | #include "hashable.h" | ||
7 | |||
8 | #define bitsToBytes( n ) (n/8+(n%8>0 ? 1 : 0)) | ||
9 | |||
10 | template<class key, class value> | ||
11 | class Hash | ||
12 | { | ||
13 | class iterator | ||
14 | { | ||
15 | friend class Hash<key, value>; | ||
16 | private: | ||
17 | iterator( Hash<key, value> *hsh, int nIndex, key keyval, bool bInsert ) : | ||
18 | hsh( hsh ), | ||
19 | nIndex( nIndex ), | ||
20 | keyval( keyval ), | ||
21 | bInsert( bInsert ) | ||
22 | { | ||
23 | } | ||
24 | |||
25 | public: | ||
26 | iterator() : | ||
27 | hsh( NULL ), | ||
28 | nIndex( -1 ) | ||
29 | { | ||
30 | } | ||
31 | |||
32 | iterator &operator=( iterator &src ) | ||
33 | { | ||
34 | this->hsh = src.hsh; | ||
35 | this->nIndex = src.nIndex; | ||
36 | } | ||
37 | |||
38 | iterator &operator=( value &src ) | ||
39 | { | ||
40 | if( bInsert ) | ||
41 | printf("You wanted to insert %d\n", src ); | ||
42 | else | ||
43 | printf("You wanted to insert %d\n", src ); | ||
44 | } | ||
45 | |||
46 | private: | ||
47 | Hash<key, value> *hsh; | ||
48 | int nIndex; | ||
49 | bool bInsert; | ||
50 | key keyval; | ||
51 | }; | ||
52 | |||
53 | template<class refval> | ||
54 | class VRef | ||
55 | { | ||
56 | public: | ||
57 | VRef( refval &data ) : | ||
58 | data( data ) | ||
59 | { | ||
60 | } | ||
61 | refval &data; | ||
62 | }; | ||
63 | |||
64 | public: | ||
65 | Hash() : | ||
66 | nCapacity( 11 ), | ||
67 | nFilled( 0 ), | ||
68 | bFilled( NULL ), | ||
69 | aKeys( NULL ), | ||
70 | aValues( NULL ), | ||
71 | aHashCodes( NULL ) | ||
72 | { | ||
73 | int nKeysSize = bitsToBytes( nCapacity ); | ||
74 | bFilled = new unsigned char[ nKeysSize ]; | ||
75 | memset( bFilled, 0, nKeysSize ); | ||
76 | |||
77 | aKeys = new VRef<key>*[nCapacity]; | ||
78 | aValues = new value[nCapacity]; | ||
79 | } | ||
80 | |||
81 | virtual ~Hash() | ||
82 | { | ||
83 | } | ||
84 | |||
85 | iterator operator[]( key keyval ) | ||
86 | { | ||
87 | //iterator i( this, 4, keyval, true ); | ||
88 | //return i; | ||
89 | printf("%s\n", keyval.getString() ); | ||
90 | } | ||
91 | |||
92 | int hasKey( key keyval ) | ||
93 | { | ||
94 | printf("%s\n", keyval.getString() ); | ||
95 | } | ||
96 | |||
97 | private: | ||
98 | int nCapacity; | ||
99 | int nFilled; | ||
100 | unsigned char *bFilled; | ||
101 | VRef<key> **aKeys; | ||
102 | unsigned long int *aHashCodes; | ||
103 | value *aValues; | ||
104 | }; | ||
105 | */ | ||
106 | #endif | ||