Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Hash_impl
diff prhash.h @ 35:dc1e44b0d702
updated include paths
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Thu, 19 Sep 2013 23:59:36 -0700 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/prhash.h Thu Sep 19 23:59:36 2013 -0700 1.3 @@ -0,0 +1,96 @@ 1.4 +/* 1.5 + * Copyright 2009 OpenSourceResearchInstitute.org 1.6 + * Licensed under GNU General Public License version 2 1.7 + * 1.8 + * Author: seanhalle@yahoo.com 1.9 + */ 1.10 + 1.11 +#ifndef _PRHASH_H 1.12 +#define _PRHASH_H 1.13 + 1.14 +#include <stdio.h> 1.15 +#include <string.h> 1.16 +#include <errno.h> 1.17 +#include <stdlib.h> 1.18 + 1.19 +#include <PR__include/PR__primitive_data_types.h> 1.20 + 1.21 +//===================== defines ===================== 1.22 +#define TRUE 1 1.23 +#define FALSE 0 1.24 + 1.25 +#define DEFAULT_HASH_TABLE_SIZE 1 << 10 1.26 +#define DEFAULT_POWER_OF_2_TABLE_SIZE 10 1.27 + 1.28 + 1.29 +//===================== structs ===================== 1.30 +union hashkey_t{ 1.31 + char hashable[8]; 1.32 + int32 parts[2]; 1.33 +}; 1.34 + 1.35 +typedef union hashkey_t hashkey_t; 1.36 + 1.37 +typedef struct _HashEntry HashEntry; 1.38 + 1.39 +struct _HashEntry 1.40 + { 1.41 + char *key; 1.42 + void *content; 1.43 + HashEntry *next; 1.44 + }; 1.45 + 1.46 +typedef void (*FreeEntryContentFnPtr) ( void * ); 1.47 + 1.48 +typedef struct 1.49 + { int32 tableSz; 1.50 + int32 numEntries; 1.51 + HashEntry* *entries; 1.52 + int32 hashMask; 1.53 + int32 prevHash; 1.54 + FreeEntryContentFnPtr freeEntryContentFn; 1.55 + } 1.56 +HashTable; 1.57 + 1.58 + 1.59 +//=========================================================================== 1.60 +// Public functions 1.61 +HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); 1.62 + 1.63 +int32 putEntryIntoTable( HashEntry *entry, HashTable *table); 1.64 +int32 addValueIntoTable( char* key, void *value, HashTable *table); 1.65 +HashEntry *getEntryFromTable( char *key, HashTable *table ); 1.66 +void *getValueFromTable( char *key, HashTable *table ); 1.67 + 1.68 +bool8 deleteEntryFromTable( char *key, HashTable *table ); 1.69 +bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); 1.70 +bool8 deleteEntrysValueInTable( char *key, HashTable *table ); 1.71 +bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); 1.72 +void freeHashTable( HashTable *table ); 1.73 +//char *paramBagToString( ParamBag * bag ) 1.74 + 1.75 +//================= Same Fns, but for 32b array key hash fn ================ 1.76 +HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); 1.77 +HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); 1.78 + 1.79 +int32 putEntryIntoTable32( HashEntry *entry, HashTable *table); 1.80 +HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table); 1.81 +HashEntry *getEntryFromTable32( uint32 key[], HashTable *table ); 1.82 +void *getValueFromTable32( uint32 key[], HashTable *table ); 1.83 + 1.84 +bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); 1.85 + 1.86 +//=========================================================================== 1.87 +// Internal functions 1.88 +void freeHashEntryUsing( HashEntry *entry, HashTable *table ); 1.89 +unsigned int hashThisKey( char *s, int hashSz ); 1.90 +void nullOutTablesArray( HashTable *table ); 1.91 +void doubleTableSize( HashTable *table ); 1.92 +void freeHashEntryButNotContent( HashEntry *entry ); 1.93 + 1.94 +uint32 1.95 +jenkHash32( const uint32 *key, /* array of uint32 values */ 1.96 + int32 length); /* num uint32 in the key */ 1.97 + 1.98 +#endif /* _PRIVATE_HASH_H */ 1.99 +
