seanhalle@3: /* seanhalle@3: * Copyright 2009 OpenSourceResearchInstitute.org seanhalle@3: * Licensed under GNU General Public License version 2 seanhalle@3: * seanhalle@3: * Author: seanhalle@yahoo.com seanhalle@3: */ seanhalle@3: seanhalle@3: #ifndef _PRHASH_H seanhalle@3: #define _PRHASH_H seanhalle@3: seanhalle@3: #include seanhalle@3: #include seanhalle@3: #include seanhalle@3: #include seanhalle@3: seanhalle@3: #include seanhalle@3: seanhalle@3: //===================== defines ===================== seanhalle@3: #define TRUE 1 seanhalle@3: #define FALSE 0 seanhalle@3: seanhalle@3: #define DEFAULT_HASH_TABLE_SIZE 1 << 10 seanhalle@3: #define DEFAULT_POWER_OF_2_TABLE_SIZE 10 seanhalle@3: seanhalle@3: seanhalle@3: //===================== structs ===================== seanhalle@3: union hashkey_t{ seanhalle@3: char hashable[8]; seanhalle@3: int32 parts[2]; seanhalle@3: }; seanhalle@3: seanhalle@3: typedef union hashkey_t hashkey_t; seanhalle@3: seanhalle@3: typedef struct _HashEntry HashEntry; seanhalle@3: seanhalle@3: struct _HashEntry seanhalle@3: { seanhalle@3: char *key; seanhalle@3: void *content; seanhalle@3: HashEntry *next; seanhalle@3: }; seanhalle@3: seanhalle@3: typedef void (*FreeEntryContentFnPtr) ( void * ); seanhalle@3: seanhalle@3: typedef struct seanhalle@3: { int32 tableSz; seanhalle@3: int32 numEntries; seanhalle@3: HashEntry* *entries; seanhalle@3: int32 hashMask; seanhalle@3: int32 prevHash; seanhalle@3: FreeEntryContentFnPtr freeEntryContentFn; seanhalle@3: } seanhalle@3: HashTable; seanhalle@3: seanhalle@3: seanhalle@3: //=========================================================================== seanhalle@3: // Public functions seanhalle@3: HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); seanhalle@3: seanhalle@3: int32 putEntryIntoTable( HashEntry *entry, HashTable *table); seanhalle@3: int32 addValueIntoTable( char* key, void *value, HashTable *table); seanhalle@3: HashEntry *getEntryFromTable( char *key, HashTable *table ); seanhalle@3: void *getValueFromTable( char *key, HashTable *table ); seanhalle@3: seanhalle@3: bool8 deleteEntryFromTable( char *key, HashTable *table ); seanhalle@3: bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); seanhalle@3: bool8 deleteEntrysValueInTable( char *key, HashTable *table ); seanhalle@3: bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); seanhalle@3: void freeHashTable( HashTable *table ); seanhalle@3: //char *paramBagToString( ParamBag * bag ) seanhalle@3: seanhalle@3: //================= Same Fns, but for 32b array key hash fn ================ seanhalle@3: HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); seanhalle@3: HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); seanhalle@3: seanhalle@3: int32 putEntryIntoTable32( HashEntry *entry, HashTable *table); seanhalle@3: HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table); seanhalle@3: HashEntry *getEntryFromTable32( uint32 key[], HashTable *table ); seanhalle@3: void *getValueFromTable32( uint32 key[], HashTable *table ); seanhalle@3: seanhalle@3: bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); seanhalle@3: seanhalle@3: //=========================================================================== seanhalle@3: // Internal functions seanhalle@3: void freeHashEntryUsing( HashEntry *entry, HashTable *table ); seanhalle@3: unsigned int hashThisKey( char *s, int hashSz ); seanhalle@3: void nullOutTablesArray( HashTable *table ); seanhalle@3: void doubleTableSize( HashTable *table ); seanhalle@3: void freeHashEntryButNotContent( HashEntry *entry ); seanhalle@3: seanhalle@3: uint32 seanhalle@3: jenkHash32( const uint32 *key, /* array of uint32 values */ seanhalle@3: int32 length); /* num uint32 in the key */ seanhalle@3: seanhalle@3: #endif /* _PRIVATE_HASH_H */ seanhalle@3: