summaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h106
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
10template<class key, class value>
11class 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
64public:
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
97private:
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