Debug swcsa
[SXSI/TextCollection.git] / lzindex / hash.h
1
2 // Closed hash table that does not store the keys
3
4 // needs the maximum number of elements stored to be declared at creation time
5 // cannot remove elements
6 // does not store the key, rather, it reports all the collisioning values
7 // right value under collisions
8 // CANNOT STORE ZERO in the value
9
10 #ifndef HASHINCLUDED
11 #define HASHINCLUDED
12
13 #include "basics.h"
14
15 typedef struct shash
16    { uint size;    // # of table entries
17      uint bits;    // bits per entry
18      uint *table;    // data
19    } *hash;
20
21 typedef uint handle;
22
23   // creates a table to store up to n values with guaranteed load factor.
24   // vbits = # of bits per entry, ENTRIES CANNOT HAVE VALUE ZERO
25 hash createHash (uint n, uint vbits, float factor);
26   // frees the structure
27 void destroyHash (hash H);
28   // inserts an entry 
29 void insertHash (hash H, uint key, uint elem);
30   // looks for a key, returns first value (zero => no values)
31   // writes in pos a handle to get next values
32 uint searchHash (hash H, uint key, handle *h);
33   // gets following values using handle *h, which is rewritten
34   // returns next value (zero => no more values)
35 uint nextHash (hash H, handle *h);
36
37         // two large primes found with etc/hash.c
38 #define PRIME1 ((uint)4294967279)
39 #define PRIME2 ((uint)4294967197)
40
41 #endif