view PrivateHash.h @ 34:049a8d8917c5

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