# HG changeset patch # User Sean Halle # Date 1379660376 25200 # Node ID dc1e44b0d70261e61514443899cf8da5f38b927e # Parent 049a8d8917c5cd08d5640813c9f414f001cc8765 updated include paths diff -r 049a8d8917c5 -r dc1e44b0d702 PrivateHash.c --- a/PrivateHash.c Tue Jul 23 07:38:54 2013 -0700 +++ b/PrivateHash.c Thu Sep 19 23:59:36 2013 -0700 @@ -6,8 +6,8 @@ * Author: seanhalle@yahoo.com */ -#include "PrivateHash.h" -#include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h" +#include +#include HashTable * makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) diff -r 049a8d8917c5 -r dc1e44b0d702 PrivateHash.h --- a/PrivateHash.h Tue Jul 23 07:38:54 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - */ - -#ifndef _PRIVATE_HASH_H -#define _PRIVATE_HASH_H - -#include -#include -#include -#include - -#include "PR__common_includes/PR__primitive_data_types.h" - -//===================== defines ===================== -#define TRUE 1 -#define FALSE 0 - -#define DEFAULT_HASH_TABLE_SIZE 1 << 10 -#define DEFAULT_POWER_OF_2_TABLE_SIZE 10 - - -//===================== structs ===================== -union hashkey_t{ - char hashable[8]; - int32 parts[2]; -}; - -typedef union hashkey_t hashkey_t; - -typedef struct _HashEntry HashEntry; - -struct _HashEntry - { - char *key; - void *content; - HashEntry *next; - }; - -typedef void (*FreeEntryContentFnPtr) ( void * ); - -typedef struct - { int32 tableSz; - int32 numEntries; - HashEntry* *entries; - int32 hashMask; - int32 prevHash; - FreeEntryContentFnPtr freeEntryContentFn; - } -HashTable; - - -//=========================================================================== -// Public functions -HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); - -int32 putEntryIntoTable( HashEntry *entry, HashTable *table); -int32 addValueIntoTable( char* key, void *value, HashTable *table); -HashEntry *getEntryFromTable( char *key, HashTable *table ); -void *getValueFromTable( char *key, HashTable *table ); - -bool8 deleteEntryFromTable( char *key, HashTable *table ); -bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); -bool8 deleteEntrysValueInTable( char *key, HashTable *table ); -bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); -void freeHashTable( HashTable *table ); -//char *paramBagToString( ParamBag * bag ) - -//================= Same Fns, but for 32b array key hash fn ================ -HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); -HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); - -int32 putEntryIntoTable32( HashEntry *entry, HashTable *table); -HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table); -HashEntry *getEntryFromTable32( uint32 key[], HashTable *table ); -void *getValueFromTable32( uint32 key[], HashTable *table ); - -bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); - -//=========================================================================== -// Internal functions -void freeHashEntryUsing( HashEntry *entry, HashTable *table ); -unsigned int hashThisKey( char *s, int hashSz ); -void nullOutTablesArray( HashTable *table ); -void doubleTableSize( HashTable *table ); -void freeHashEntryButNotContent( HashEntry *entry ); - -uint32 -jenkHash32( const uint32 *key, /* array of uint32 values */ - int32 length); /* num uint32 in the key */ - -#endif /* _PRIVATE_HASH_H */ - diff -r 049a8d8917c5 -r dc1e44b0d702 prhash.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prhash.h Thu Sep 19 23:59:36 2013 -0700 @@ -0,0 +1,96 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + */ + +#ifndef _PRHASH_H +#define _PRHASH_H + +#include +#include +#include +#include + +#include + +//===================== defines ===================== +#define TRUE 1 +#define FALSE 0 + +#define DEFAULT_HASH_TABLE_SIZE 1 << 10 +#define DEFAULT_POWER_OF_2_TABLE_SIZE 10 + + +//===================== structs ===================== +union hashkey_t{ + char hashable[8]; + int32 parts[2]; +}; + +typedef union hashkey_t hashkey_t; + +typedef struct _HashEntry HashEntry; + +struct _HashEntry + { + char *key; + void *content; + HashEntry *next; + }; + +typedef void (*FreeEntryContentFnPtr) ( void * ); + +typedef struct + { int32 tableSz; + int32 numEntries; + HashEntry* *entries; + int32 hashMask; + int32 prevHash; + FreeEntryContentFnPtr freeEntryContentFn; + } +HashTable; + + +//=========================================================================== +// Public functions +HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); + +int32 putEntryIntoTable( HashEntry *entry, HashTable *table); +int32 addValueIntoTable( char* key, void *value, HashTable *table); +HashEntry *getEntryFromTable( char *key, HashTable *table ); +void *getValueFromTable( char *key, HashTable *table ); + +bool8 deleteEntryFromTable( char *key, HashTable *table ); +bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); +bool8 deleteEntrysValueInTable( char *key, HashTable *table ); +bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); +void freeHashTable( HashTable *table ); +//char *paramBagToString( ParamBag * bag ) + +//================= Same Fns, but for 32b array key hash fn ================ +HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); +HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); + +int32 putEntryIntoTable32( HashEntry *entry, HashTable *table); +HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table); +HashEntry *getEntryFromTable32( uint32 key[], HashTable *table ); +void *getValueFromTable32( uint32 key[], HashTable *table ); + +bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); + +//=========================================================================== +// Internal functions +void freeHashEntryUsing( HashEntry *entry, HashTable *table ); +unsigned int hashThisKey( char *s, int hashSz ); +void nullOutTablesArray( HashTable *table ); +void doubleTableSize( HashTable *table ); +void freeHashEntryButNotContent( HashEntry *entry ); + +uint32 +jenkHash32( const uint32 *key, /* array of uint32 values */ + int32 length); /* num uint32 in the key */ + +#endif /* _PRIVATE_HASH_H */ +