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