| rev |
line source |
|
Me@15
|
1 /*
|
|
Me@15
|
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
|
|
Me@15
|
3 * Licensed under GNU General Public License version 2
|
|
Me@15
|
4 *
|
|
Me@15
|
5 * Author: seanhalle@yahoo.com
|
|
Me@15
|
6 */
|
|
Me@15
|
7
|
|
Me@15
|
8 #ifndef _PRIVATE_HASH_H
|
|
Me@15
|
9 #define _PRIVATE_HASH_H
|
|
Me@15
|
10
|
|
Me@15
|
11
|
|
Me@15
|
12 #include <stdio.h>
|
|
Me@15
|
13 #include <string.h>
|
|
Me@15
|
14 #include <errno.h>
|
|
Me@15
|
15 #include <stdlib.h>
|
|
Me@15
|
16
|
|
Me@15
|
17 #define TRUE 1
|
|
Me@15
|
18 #define FALSE 0
|
|
Me@15
|
19
|
|
Me@15
|
20 union hashkey_t{
|
|
Me@15
|
21 char hashable[8];
|
|
Me@15
|
22 int parts[2];
|
|
Me@15
|
23 };
|
|
Me@15
|
24
|
|
Me@15
|
25 typedef union hashkey_t hashkey_t;
|
|
Me@15
|
26
|
|
Me@15
|
27 #define DEFAULT_HASHSIZE 1 << 10
|
|
Me@15
|
28
|
|
Me@15
|
29 typedef struct _HashEntry HashEntry;
|
|
Me@15
|
30
|
|
Me@15
|
31 struct _HashEntry
|
|
Me@15
|
32 {
|
|
Me@15
|
33 char *key;
|
|
Me@15
|
34 void *content;
|
|
Me@15
|
35 HashEntry *next;
|
|
Me@15
|
36 };
|
|
Me@15
|
37
|
|
Me@15
|
38 typedef void (*FreeEntryContentFnPtr) ( void * );
|
|
Me@15
|
39
|
|
Me@15
|
40 typedef struct
|
|
Me@15
|
41 { int tableSz;
|
|
Me@15
|
42 int numEntries;
|
|
Me@15
|
43 HashEntry* *entries;
|
|
Me@15
|
44 FreeEntryContentFnPtr freeEntryContentFn;
|
|
Me@15
|
45 }
|
|
Me@15
|
46 HashTable;
|
|
Me@15
|
47
|
|
Me@15
|
48
|
|
Me@15
|
49 //===========================================================================
|
|
Me@15
|
50 // Public functions
|
|
Me@15
|
51 HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn );
|
|
Me@15
|
52
|
|
Me@15
|
53 int putEntryIntoTable( HashEntry *entry, HashTable *table);
|
|
Me@15
|
54 int addValueIntoTable( char* key, void *value, HashTable *table);
|
|
Me@15
|
55 HashEntry *getEntryFromTable( char *key, HashTable *table );
|
|
Me@15
|
56 void *getValueFromTable( char *key, HashTable *table );
|
|
Me@15
|
57
|
|
Me@15
|
58 bool8 deleteEntryFromTable( char *key, HashTable *table );
|
|
Me@15
|
59 bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table );
|
|
Me@15
|
60 bool8 deleteEntrysValueInTable( char *key, HashTable *table );
|
|
Me@15
|
61 bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table );
|
|
Me@15
|
62 void freeHashTable( HashTable *table );
|
|
Me@15
|
63 //char *paramBagToString( ParamBag * bag )
|
|
Me@15
|
64
|
|
Me@15
|
65 //===========================================================================
|
|
Me@15
|
66 // Internal functions
|
|
Me@15
|
67 void freeHashEntryUsing( HashEntry *entry, HashTable *table );
|
|
Me@15
|
68 unsigned int hashThisKey( char *s, int hashSz );
|
|
Me@15
|
69 void nullOutTablesArray( HashTable *table );
|
|
Me@15
|
70 void doubleTableSize( HashTable *table );
|
|
Me@15
|
71 void freeHashEntryButNotContent( HashEntry *entry );
|
|
Me@15
|
72
|
|
Me@15
|
73 #endif /* _PRIVATE_HASH_H */
|
|
Me@15
|
74
|