view PrivateHash.h @ 31:1d42a512f482

Renamed VMS to PR, in new branch
author Sean Halle <seanhalle@yahoo.com>
date Fri, 08 Mar 2013 05:44:24 -0800
parents 18ec64d06e35
children 097d8ccb18b7
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_impl/PR_primitive_data_types.h"
17 #include "PR_impl/Services_Offered_by_PR/Memory_Handling/vmalloc.h"
19 //===================== defines =====================
20 #define TRUE 1
21 #define FALSE 0
23 #define DEFAULT_HASH_TABLE_SIZE 1 << 10
24 #define DEFAULT_POWER_OF_2_TABLE_SIZE 10
27 //===================== structs =====================
28 union hashkey_t{
29 char hashable[8];
30 int32 parts[2];
31 };
33 typedef union hashkey_t hashkey_t;
35 typedef struct _HashEntry HashEntry;
37 struct _HashEntry
38 {
39 char *key;
40 void *content;
41 HashEntry *next;
42 };
44 typedef void (*FreeEntryContentFnPtr) ( void * );
46 typedef struct
47 { int32 tableSz;
48 int32 numEntries;
49 HashEntry* *entries;
50 int32 hashMask;
51 int32 prevHash;
52 FreeEntryContentFnPtr freeEntryContentFn;
53 }
54 HashTable;
57 //===========================================================================
58 // Public functions
59 HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn );
61 int32 putEntryIntoTable( HashEntry *entry, HashTable *table);
62 int32 addValueIntoTable( char* key, void *value, HashTable *table);
63 HashEntry *getEntryFromTable( char *key, HashTable *table );
64 void *getValueFromTable( char *key, HashTable *table );
66 bool8 deleteEntryFromTable( char *key, HashTable *table );
67 bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table );
68 bool8 deleteEntrysValueInTable( char *key, HashTable *table );
69 bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table );
70 void freeHashTable( HashTable *table );
71 //char *paramBagToString( ParamBag * bag )
73 //================= Same Fns, but for 32b array key hash fn ================
74 HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn);
75 HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn );
77 int32 putEntryIntoTable32( HashEntry *entry, HashTable *table);
78 HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table);
79 HashEntry *getEntryFromTable32( uint32 key[], HashTable *table );
80 void *getValueFromTable32( uint32 key[], HashTable *table );
82 bool32 deleteEntryFromTable32( uint32 key[], HashTable *table );
84 //===========================================================================
85 // Internal functions
86 void freeHashEntryUsing( HashEntry *entry, HashTable *table );
87 unsigned int hashThisKey( char *s, int hashSz );
88 void nullOutTablesArray( HashTable *table );
89 void doubleTableSize( HashTable *table );
90 void freeHashEntryButNotContent( HashEntry *entry );
92 uint32
93 jenkHash32( const uint32 *key, /* array of uint32 values */
94 int32 length); /* num uint32 in the key */
96 #endif /* _PRIVATE_HASH_H */