annotate prhash.h @ 4:10986666560d

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