| rev |
line source |
|
seanhalle@35
|
1 /*
|
|
seanhalle@35
|
2 * Copyright 2009 OpenSourceResearchInstitute.org
|
|
seanhalle@35
|
3 * Licensed under GNU General Public License version 2
|
|
seanhalle@35
|
4 *
|
|
seanhalle@35
|
5 * Author: seanhalle@yahoo.com
|
|
seanhalle@35
|
6 */
|
|
seanhalle@35
|
7
|
|
seanhalle@35
|
8 #ifndef _PRHASH_H
|
|
seanhalle@35
|
9 #define _PRHASH_H
|
|
seanhalle@35
|
10
|
|
seanhalle@35
|
11 #include <stdio.h>
|
|
seanhalle@35
|
12 #include <string.h>
|
|
seanhalle@35
|
13 #include <errno.h>
|
|
seanhalle@35
|
14 #include <stdlib.h>
|
|
seanhalle@35
|
15
|
|
seanhalle@35
|
16 #include <PR__include/PR__primitive_data_types.h>
|
|
seanhalle@35
|
17
|
|
seanhalle@35
|
18 //===================== defines =====================
|
|
seanhalle@35
|
19 #define TRUE 1
|
|
seanhalle@35
|
20 #define FALSE 0
|
|
seanhalle@35
|
21
|
|
seanhalle@35
|
22 #define DEFAULT_HASH_TABLE_SIZE 1 << 10
|
|
seanhalle@35
|
23 #define DEFAULT_POWER_OF_2_TABLE_SIZE 10
|
|
seanhalle@35
|
24
|
|
seanhalle@35
|
25
|
|
seanhalle@35
|
26 //===================== structs =====================
|
|
seanhalle@35
|
27 union hashkey_t{
|
|
seanhalle@35
|
28 char hashable[8];
|
|
seanhalle@35
|
29 int32 parts[2];
|
|
seanhalle@35
|
30 };
|
|
seanhalle@35
|
31
|
|
seanhalle@35
|
32 typedef union hashkey_t hashkey_t;
|
|
seanhalle@35
|
33
|
|
seanhalle@35
|
34 typedef struct _HashEntry HashEntry;
|
|
seanhalle@35
|
35
|
|
seanhalle@35
|
36 struct _HashEntry
|
|
seanhalle@35
|
37 {
|
|
seanhalle@35
|
38 char *key;
|
|
seanhalle@35
|
39 void *content;
|
|
seanhalle@35
|
40 HashEntry *next;
|
|
seanhalle@35
|
41 };
|
|
seanhalle@35
|
42
|
|
seanhalle@35
|
43 typedef void (*FreeEntryContentFnPtr) ( void * );
|
|
seanhalle@35
|
44
|
|
seanhalle@35
|
45 typedef struct
|
|
seanhalle@35
|
46 { int32 tableSz;
|
|
seanhalle@35
|
47 int32 numEntries;
|
|
seanhalle@35
|
48 HashEntry* *entries;
|
|
seanhalle@35
|
49 int32 hashMask;
|
|
seanhalle@35
|
50 int32 prevHash;
|
|
seanhalle@35
|
51 FreeEntryContentFnPtr freeEntryContentFn;
|
|
seanhalle@35
|
52 }
|
|
seanhalle@35
|
53 HashTable;
|
|
seanhalle@35
|
54
|
|
seanhalle@35
|
55
|
|
seanhalle@35
|
56 //===========================================================================
|
|
seanhalle@35
|
57 // Public functions
|
|
seanhalle@35
|
58 HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn );
|
|
seanhalle@35
|
59
|
|
seanhalle@35
|
60 int32 putEntryIntoTable( HashEntry *entry, HashTable *table);
|
|
seanhalle@35
|
61 int32 addValueIntoTable( char* key, void *value, HashTable *table);
|
|
seanhalle@35
|
62 HashEntry *getEntryFromTable( char *key, HashTable *table );
|
|
seanhalle@35
|
63 void *getValueFromTable( char *key, HashTable *table );
|
|
seanhalle@35
|
64
|
|
seanhalle@35
|
65 bool8 deleteEntryFromTable( char *key, HashTable *table );
|
|
seanhalle@35
|
66 bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table );
|
|
seanhalle@35
|
67 bool8 deleteEntrysValueInTable( char *key, HashTable *table );
|
|
seanhalle@35
|
68 bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table );
|
|
seanhalle@35
|
69 void freeHashTable( HashTable *table );
|
|
seanhalle@35
|
70 //char *paramBagToString( ParamBag * bag )
|
|
seanhalle@35
|
71
|
|
seanhalle@35
|
72 //================= Same Fns, but for 32b array key hash fn ================
|
|
seanhalle@35
|
73 HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn);
|
|
seanhalle@35
|
74 HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn );
|
|
seanhalle@35
|
75
|
|
seanhalle@35
|
76 int32 putEntryIntoTable32( HashEntry *entry, HashTable *table);
|
|
seanhalle@35
|
77 HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table);
|
|
seanhalle@35
|
78 HashEntry *getEntryFromTable32( uint32 key[], HashTable *table );
|
|
seanhalle@35
|
79 void *getValueFromTable32( uint32 key[], HashTable *table );
|
|
seanhalle@35
|
80
|
|
seanhalle@35
|
81 bool32 deleteEntryFromTable32( uint32 key[], HashTable *table );
|
|
seanhalle@35
|
82
|
|
seanhalle@35
|
83 //===========================================================================
|
|
seanhalle@35
|
84 // Internal functions
|
|
seanhalle@35
|
85 void freeHashEntryUsing( HashEntry *entry, HashTable *table );
|
|
seanhalle@35
|
86 unsigned int hashThisKey( char *s, int hashSz );
|
|
seanhalle@35
|
87 void nullOutTablesArray( HashTable *table );
|
|
seanhalle@35
|
88 void doubleTableSize( HashTable *table );
|
|
seanhalle@35
|
89 void freeHashEntryButNotContent( HashEntry *entry );
|
|
seanhalle@35
|
90
|
|
seanhalle@35
|
91 uint32
|
|
seanhalle@35
|
92 jenkHash32( const uint32 *key, /* array of uint32 values */
|
|
seanhalle@35
|
93 int32 length); /* num uint32 in the key */
|
|
seanhalle@35
|
94
|
|
seanhalle@35
|
95 #endif /* _PRIVATE_HASH_H */
|
|
seanhalle@35
|
96
|