Back to index

libcitadel  8.12
Classes | Typedefs | Functions
hash.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include "libcitadel.h"
#include "lookup3.h"

Go to the source code of this file.

Classes

struct  Payload
 Hash Payload storage Structure; filled in linear. More...
struct  HashKey
 Hash key element; sorted by key. More...
struct  HashList
 Hash structure; holds arrays of Hashkey and Payload. More...
struct  HashPos
 Anonymous Hash Iterator Object. More...

Typedefs

typedef struct Payload

Functions

int PrintHash (HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry)
 Iterate over the hash and call PrintEntry.
int dbg_PrintHash (HashList *Hash, PrintHashContent First, PrintHashContent Second)
 verify the contents of a hash list; here for debugging purposes.
int TestValidateHash (HashList *TestHash)
HashListNewHash (int Uniq, HashFunc F)
 instanciate a new hashlist
int GetCount (HashList *Hash)
static void DeleteHashPayload (Payload *Data)
 private destructor for one hash element.
void HDeleteHash (void *vHash)
 Destructor for nested hashes.
void DeleteHashContent (HashList **Hash)
 flush the members of a hashlist Crashing? do 'print *FreeMe->LookupTable[i]'
void DeleteHash (HashList **Hash)
 destroy a hashlist and all of its members Crashing? do 'print *FreeMe->LookupTable[i]'
static void IncreaseHashSize (HashList *Hash)
 Private function to increase the hash size.
static void InsertHashItem (HashList *Hash, long HashPos, long HashBinKey, const char *HashKeyStr, long HKLen, void *Data, DeleteHashDataFunc Destructor)
 private function to add a new item to / replace an existing in - the hashlist if the hash list is full, its re-alloced with double size.
static long FindInTaintedHash (HashList *Hash, long HashBinKey)
 if the user has tainted the hash, but wants to insert / search items by their key we need to search linear through the array.
static long FindInHash (HashList *Hash, long HashBinKey)
 Private function to lookup the Item / the closest position to put it in.
long Flathash (const char *str, long len)
 another hashing algorithm; treat it as just a pointer to int.
long lFlathash (const char *str, long len)
 another hashing algorithm; treat it as just a pointer to long.
static long CalcHashKey (HashList *Hash, const char *HKey, long HKLen)
 private abstract wrapper around the hashing algorithm
void Put (HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt)
 Add a new / Replace an existing item in the Hash.
int GetHash (HashList *Hash, const char *HKey, long HKLen, void **Data)
 Lookup the Data associated with HKey.
int GetKey (HashList *Hash, char *HKey, long HKLen, void **Payload)
int GetHashKeys (HashList *Hash, char ***List)
 get the Keys present in this hash, simila to array_keys() in PHP Attention: List remains to Hash! don't modify or free it!
HashPosGetNewHashPos (HashList *Hash, int StepWidth)
 creates a hash-linear iterator object
int GetHashPosFromKey (HashList *Hash, const char *HKey, long HKLen, HashPos *At)
 Set iterator object to point to key.
int DeleteEntryFromHash (HashList *Hash, HashPos *At)
 Delete from the Hash the entry at Position.
int GetHashPosCounter (HashList *Hash, HashPos *At)
 retrieve the counter from the itteratoor
void DeleteHashPos (HashPos **DelMe)
 frees a linear hash iterator
int GetNextHashPos (HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data)
 Get the data located where HashPos Iterator points at, and Move HashPos one forward.
int GetHashPos (HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data)
 Get the data located where HashPos Iterator points at.
int NextHashPos (HashList *Hash, HashPos *At)
 Move HashPos one forward.
int GetHashAt (HashList *Hash, long At, long *HKLen, const char **HashKey, void **Data)
 Get the data located where At points to note: you should prefer iterator operations instead of using me.
static int SortByKeys (const void *Key1, const void *Key2)
 Get the data located where At points to note: you should prefer iterator operations instead of using me.
static int SortByKeysRev (const void *Key1, const void *Key2)
 sorting function for sorting the Hash alphabeticaly reverse by their strings
static int SortByHashKeys (const void *Key1, const void *Key2)
 sorting function to regain hash-sequence and revert tainted status
void SortByHashKey (HashList *Hash, int Order)
 sort the hash alphabeticaly by their keys.
void SortByHashKeyStr (HashList *Hash)
 sort the hash by their keys (so it regains untainted state).
const void * GetSearchPayload (const void *HashVoid)
 gives user sort routines access to the hash payload
void SortByPayload (HashList *Hash, CompareFunc SortBy)
 sort the hash by your sort function.
void reference_free_handler (void *ptr)
 given you've put char * into your hash as a payload, a sort function might look like this: int SortByChar(const void* First, const void* Second) { char a, b; a = (char) GetSearchPayload(First); b = (char) GetSearchPayload(Second); return strcmp (a, b); }
int HashLittle (const void *key, size_t length)
 This exposes the hashlittle() function to consumers.
int ParseMSet (MSet **MSetList, StrBuf *MSetStr)
 parses an MSet string into a list for later use
int IsInMSetList (MSet *MSetList, long MsgNo)
 checks whether a message is inside a mset
void DeleteMSet (MSet **FreeMe)
 frees a mset [redirects to DeleteHash

Typedef Documentation

typedef struct Payload

Definition at line 28 of file hash.c.


Function Documentation

int GetCount ( HashList Hash)

Definition at line 292 of file hash.c.

{
       if(Hash==NULL) return 0;
       return Hash->nLookupTableItems;
}

Here is the caller graph for this function:

int GetKey ( HashList Hash,
char *  HKey,
long  HKLen,
void **  Payload 
)

Definition at line 706 of file hash.c.

{
       return 0;
}
int TestValidateHash ( HashList TestHash)

Definition at line 243 of file hash.c.

{
       long i;

       if (TestHash->nMembersUsed != TestHash->nLookupTableItems)
              return 1;

       if (TestHash->nMembersUsed > TestHash->MemberSize)
              return 2;

       for (i=0; i < TestHash->nMembersUsed; i++)
       {

              if (TestHash->LookupTable[i]->Position > TestHash->nMembersUsed)
                     return 3;
              
              if (TestHash->Members[TestHash->LookupTable[i]->Position] == NULL)
                     return 4;
              if (TestHash->Members[TestHash->LookupTable[i]->Position]->Data == NULL)
                     return 5;
       }
       return 0;
}