annotate prhash.h @ 5:c390d605702c

Merge
author Sean Halle <seanhalle@yahoo.com>
date Sun, 15 Sep 2013 07:20:10 -0700
parents 14241f07f742
children f3cb11baf791
rev   line source
seanhalle@3 1 /*
seanhalle@3 2 * Copyright 2009 OpenSourceResearchInstitute.org
seanhalle@3 3 * Licensed under GNU General Public License version 2
seanhalle@3 4 *
seanhalle@3 5 * Author: seanhalle@yahoo.com
seanhalle@3 6 */
seanhalle@3 7
seanhalle@3 8 #ifndef _PRHASH_H
seanhalle@3 9 #define _PRHASH_H
seanhalle@3 10
seanhalle@3 11 #include <stdio.h>
seanhalle@3 12 #include <string.h>
seanhalle@3 13 #include <errno.h>
seanhalle@3 14 #include <stdlib.h>
seanhalle@3 15
seanhalle@3 16 #include <PR__include/PR__primitive_data_types.h>
seanhalle@3 17
seanhalle@3 18 //===================== defines =====================
seanhalle@3 19 #define TRUE 1
seanhalle@3 20 #define FALSE 0
seanhalle@3 21
seanhalle@3 22 #define DEFAULT_HASH_TABLE_SIZE 1 << 10
seanhalle@3 23 #define DEFAULT_POWER_OF_2_TABLE_SIZE 10
seanhalle@3 24
seanhalle@3 25
seanhalle@3 26 //===================== structs =====================
seanhalle@3 27 union hashkey_t{
seanhalle@3 28 char hashable[8];
seanhalle@3 29 int32 parts[2];
seanhalle@3 30 };
seanhalle@3 31
seanhalle@3 32 typedef union hashkey_t hashkey_t;
seanhalle@3 33
seanhalle@3 34 typedef struct _HashEntry HashEntry;
seanhalle@3 35
seanhalle@3 36 struct _HashEntry
seanhalle@3 37 {
seanhalle@3 38 char *key;
seanhalle@3 39 void *content;
seanhalle@3 40 HashEntry *next;
seanhalle@3 41 };
seanhalle@3 42
seanhalle@3 43 typedef void (*FreeEntryContentFnPtr) ( void * );
seanhalle@3 44
seanhalle@3 45 typedef struct
seanhalle@3 46 { int32 tableSz;
seanhalle@3 47 int32 numEntries;
seanhalle@3 48 HashEntry* *entries;
seanhalle@3 49 int32 hashMask;
seanhalle@3 50 int32 prevHash;
seanhalle@3 51 FreeEntryContentFnPtr freeEntryContentFn;
seanhalle@3 52 }
seanhalle@3 53 HashTable;
seanhalle@3 54
seanhalle@3 55
seanhalle@3 56 //===========================================================================
seanhalle@3 57 // Public functions
seanhalle@3 58 HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn );
seanhalle@3 59
seanhalle@3 60 int32 putEntryIntoTable( HashEntry *entry, HashTable *table);
seanhalle@3 61 int32 addValueIntoTable( char* key, void *value, HashTable *table);
seanhalle@3 62 HashEntry *getEntryFromTable( char *key, HashTable *table );
seanhalle@3 63 void *getValueFromTable( char *key, HashTable *table );
seanhalle@3 64
seanhalle@3 65 bool8 deleteEntryFromTable( char *key, HashTable *table );
seanhalle@3 66 bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table );
seanhalle@3 67 bool8 deleteEntrysValueInTable( char *key, HashTable *table );
seanhalle@3 68 bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table );
seanhalle@3 69 void freeHashTable( HashTable *table );
seanhalle@3 70 //char *paramBagToString( ParamBag * bag )
seanhalle@3 71
seanhalle@3 72 //================= Same Fns, but for 32b array key hash fn ================
seanhalle@3 73 HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn);
seanhalle@3 74 HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn );
seanhalle@3 75
seanhalle@3 76 int32 putEntryIntoTable32( HashEntry *entry, HashTable *table);
seanhalle@3 77 HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table);
seanhalle@3 78 HashEntry *getEntryFromTable32( uint32 key[], HashTable *table );
seanhalle@3 79 void *getValueFromTable32( uint32 key[], HashTable *table );
seanhalle@3 80
seanhalle@3 81 bool32 deleteEntryFromTable32( uint32 key[], HashTable *table );
seanhalle@3 82
seanhalle@3 83 //===========================================================================
seanhalle@3 84 // Internal functions
seanhalle@3 85 void freeHashEntryUsing( HashEntry *entry, HashTable *table );
seanhalle@3 86 unsigned int hashThisKey( char *s, int hashSz );
seanhalle@3 87 void nullOutTablesArray( HashTable *table );
seanhalle@3 88 void doubleTableSize( HashTable *table );
seanhalle@3 89 void freeHashEntryButNotContent( HashEntry *entry );
seanhalle@3 90
seanhalle@3 91 uint32
seanhalle@3 92 jenkHash32( const uint32 *key, /* array of uint32 values */
seanhalle@3 93 int32 length); /* num uint32 in the key */
seanhalle@3 94
seanhalle@3 95 #endif /* _PRIVATE_HASH_H */
seanhalle@3 96