Back to index

libcitadel  8.12
Functions
Hashlist sorting functions
Hashlist Key Value list implementation;
Collaboration diagram for Hashlist sorting functions:

Functions

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 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.

Function Documentation

static long FindInTaintedHash ( HashList Hash,
long  HashBinKey 
) [static]

if the user has tainted the hash, but wants to insert / search items by their key we need to search linear through the array.

You have been warned that this will take more time!

Parameters:
HashOur Hash to manipulate
HashBinKeythe Hash-Number to lookup.
Returns:
the position (most closely) matching HashBinKey (-> Caller needs to compare! )

Definition at line 500 of file hash.c.

{
       long SearchPos;

       if (Hash == NULL)
              return 0;

       for (SearchPos = 0; SearchPos < Hash->nLookupTableItems; SearchPos ++) {
              if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
                     return SearchPos;
              }
       }
       return SearchPos;
}

Here is the caller graph for this function:

const void* GetSearchPayload ( const void *  HashVoid)

gives user sort routines access to the hash payload

Parameters:
HashVoidto retrieve Data to
Returns:
Data belonging to HashVoid

Definition at line 1102 of file hash.c.

{
       return (*(HashKey**)HashVoid)->PL->Data;
}
void SortByHashKey ( HashList Hash,
int  Order 
)

sort the hash alphabeticaly by their keys.

Caution: This taints the hashlist, so accessing it later will be significantly slower! You can un-taint it by SortByHashKeyStr

Parameters:
Hashthe list to sort
Order0/1 Forward/Backward

Definition at line 1072 of file hash.c.

{
       if (Hash->nLookupTableItems < 2)
              return;
       qsort(Hash->LookupTable, Hash->nLookupTableItems, sizeof(HashKey*), 
             (Order)?SortByKeys:SortByKeysRev);
       Hash->tainted = 1;
}

Here is the call graph for this function:

static int SortByHashKeys ( const void *  Key1,
const void *  Key2 
) [static]

sorting function to regain hash-sequence and revert tainted status

Parameters:
Key1first item
Key2second item

Definition at line 1054 of file hash.c.

{
       HashKey *HKey1, *HKey2;
       HKey1 = *(HashKey**) Key1;
       HKey2 = *(HashKey**) Key2;

       return HKey1->Key > HKey2->Key;
}

Here is the caller graph for this function:

void SortByHashKeyStr ( HashList Hash)

sort the hash by their keys (so it regains untainted state).

this will result in the sequence the hashing allgorithm produces it by default.

Parameters:
Hashthe list to sort

Definition at line 1087 of file hash.c.

{
       Hash->tainted = 0;
       if (Hash->nLookupTableItems < 2)
              return;
       qsort(Hash->LookupTable, Hash->nLookupTableItems, sizeof(HashKey*), SortByHashKeys);
}

Here is the call graph for this function:

static int SortByKeys ( const void *  Key1,
const void *  Key2 
) [static]

Get the data located where At points to note: you should prefer iterator operations instead of using me.

Parameters:
Hashyour Hashlist peek from
HKLenreturns Length of Hashkey Returned
HashKeyreturns the Hashkey corrosponding to HashPos
Datareturns the Data found at HashPos
Returns:
whether the item was found or not.

sorting function for sorting the Hash alphabeticaly by their strings

Parameters:
Key1first item
Key2second item

Definition at line 1024 of file hash.c.

{
       HashKey *HKey1, *HKey2;
       HKey1 = *(HashKey**) Key1;
       HKey2 = *(HashKey**) Key2;

       return strcasecmp(HKey1->HashKey, HKey2->HashKey);
}

Here is the caller graph for this function:

static int SortByKeysRev ( const void *  Key1,
const void *  Key2 
) [static]

sorting function for sorting the Hash alphabeticaly reverse by their strings

Parameters:
Key1first item
Key2second item

Definition at line 1039 of file hash.c.

{
       HashKey *HKey1, *HKey2;
       HKey1 = *(HashKey**) Key1;
       HKey2 = *(HashKey**) Key2;

       return strcasecmp(HKey2->HashKey, HKey1->HashKey);
}

Here is the caller graph for this function:

void SortByPayload ( HashList Hash,
CompareFunc  SortBy 
)

sort the hash by your sort function.

see the following sample. this will result in the sequence the hashing allgorithm produces it by default.

Parameters:
Hashthe list to sort
SortBySortfunction; see below how to implement this

Definition at line 1114 of file hash.c.

{
       if (Hash->nLookupTableItems < 2)
              return;
       qsort(Hash->LookupTable, Hash->nLookupTableItems, sizeof(HashKey*), SortBy);
       Hash->tainted = 1;
}