/*
 *  Copyright 2009 OpenSourceStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 *
 * Author: seanhalle@yahoo.com
 */

#ifndef _PRIVATE_HASH_H
#define	_PRIVATE_HASH_H


#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

#define TRUE     1
#define FALSE    0

union hashkey_t{
    char hashable[8];
    int  parts[2];
};

typedef union hashkey_t hashkey_t;

#define DEFAULT_HASHSIZE 1 << 10

typedef struct _HashEntry HashEntry;

struct _HashEntry
 {
   char       *key;
   void       *content;
   HashEntry  *next;
 };

typedef void (*FreeEntryContentFnPtr)    ( void * );

typedef struct
 { int tableSz;
   int numEntries;
   HashEntry* *entries;
   FreeEntryContentFnPtr freeEntryContentFn;
 }
HashTable;


//===========================================================================
//   Public functions
HashTable   *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn );

int          putEntryIntoTable( HashEntry *entry, HashTable *table);
int          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 )

//===========================================================================
//   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 );

#endif	/* _PRIVATE_HASH_H */

