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