Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Hash_impl
comparison prhash.h @ 37:c21c30e45a17
changed name of netbeans proj dirs
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Fri, 14 Feb 2014 07:14:08 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:2c3d7399a3a6 |
|---|---|
| 1 /* | |
| 2 * Copyright 2009 OpenSourceResearchInstitute.org | |
| 3 * Licensed under GNU General Public License version 2 | |
| 4 * | |
| 5 * Author: seanhalle@yahoo.com | |
| 6 */ | |
| 7 | |
| 8 #ifndef _PRHASH_H | |
| 9 #define _PRHASH_H | |
| 10 | |
| 11 #include <stdio.h> | |
| 12 #include <string.h> | |
| 13 #include <errno.h> | |
| 14 #include <stdlib.h> | |
| 15 | |
| 16 #include <PR__include/PR__primitive_data_types.h> | |
| 17 | |
| 18 //===================== defines ===================== | |
| 19 #define TRUE 1 | |
| 20 #define FALSE 0 | |
| 21 | |
| 22 #define DEFAULT_HASH_TABLE_SIZE 1 << 10 | |
| 23 #define DEFAULT_POWER_OF_2_TABLE_SIZE 10 | |
| 24 | |
| 25 | |
| 26 //===================== structs ===================== | |
| 27 union hashkey_t{ | |
| 28 char hashable[8]; | |
| 29 int32 parts[2]; | |
| 30 }; | |
| 31 | |
| 32 typedef union hashkey_t hashkey_t; | |
| 33 | |
| 34 typedef struct _HashEntry HashEntry; | |
| 35 | |
| 36 struct _HashEntry | |
| 37 { | |
| 38 char *key; | |
| 39 void *content; | |
| 40 HashEntry *next; | |
| 41 }; | |
| 42 | |
| 43 typedef void (*FreeEntryContentFnPtr) ( void * ); | |
| 44 | |
| 45 typedef struct | |
| 46 { int32 tableSz; | |
| 47 int32 numEntries; | |
| 48 HashEntry* *entries; | |
| 49 int32 hashMask; | |
| 50 int32 prevHash; | |
| 51 FreeEntryContentFnPtr freeEntryContentFn; | |
| 52 } | |
| 53 HashTable; | |
| 54 | |
| 55 | |
| 56 //=========================================================================== | |
| 57 // Public functions | |
| 58 HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); | |
| 59 | |
| 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 ); | |
| 64 | |
| 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 ) | |
| 71 | |
| 72 //================= Same Fns, but for 32b array key hash fn ================ | |
| 73 HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); | |
| 74 HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); | |
| 75 | |
| 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 ); | |
| 80 | |
| 81 bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); | |
| 82 | |
| 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 ); | |
| 90 | |
| 91 uint32 | |
| 92 jenkHash32( const uint32 *key, /* array of uint32 values */ | |
| 93 int32 length); /* num uint32 in the key */ | |
| 94 | |
| 95 #endif /* _PRIVATE_HASH_H */ | |
| 96 |
