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