annotate prhash.h @ 1:14241f07f742

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