annotate prhash.h @ 22:d8f96a3bbea4

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