Back to index

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

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.

Function Documentation

int dbg_PrintHash ( HashList Hash,
PrintHashContent  First,
PrintHashContent  Second 
)

verify the contents of a hash list; here for debugging purposes.

Parameters:
Hashyour Hashlist structure
FirstFunctionpointer to allow you to print your payload
SecondFunctionpointer to allow you to print your payload
Returns:
0

Definition at line 174 of file hash.c.

{
#ifdef DEBUG
       const char *foo;
       const char *bar;
       const char *bla = "";
       long key;
#endif
       long i;

       if (Hash == NULL)
              return 0;

       if (Hash->MyKeys != NULL)
              free (Hash->MyKeys);

       Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nLookupTableItems);
#ifdef DEBUG
       printf("----------------------------------\n");
#endif
       for (i=0; i < Hash->nLookupTableItems; i++) {
              
              if (Hash->LookupTable[i] == NULL)
              {
#ifdef DEBUG
                     foo = "";
                     bar = "";
                     key = 0;
#endif
              }
              else 
              {
#ifdef DEBUG
                     key = Hash->LookupTable[i]->Key;
                     foo = Hash->LookupTable[i]->HashKey;
#endif
                     if (First != NULL)
#ifdef DEBUG
                            bar =
#endif
                                   First(Hash->Members[Hash->LookupTable[i]->Position]->Data);
#ifdef DEBUG
                     else 
                            bar = "";
#endif

                     if (Second != NULL)
#ifdef DEBUG
                            bla = 
#endif 
                                   Second(Hash->Members[Hash->LookupTable[i]->Position]->Data);
#ifdef DEBUG

                     else
                            bla = "";
#endif

              }
#ifdef DEBUG
              printf (" ---- Hashkey[%ld][%ld]: '%s' Value: '%s' ; %s\n", i, key, foo, bar, bla);
#endif
       }
#ifdef DEBUG
       printf("----------------------------------\n");
#endif
       return 0;
}
int PrintHash ( HashList Hash,
TransitionFunc  Trans,
PrintHashDataFunc  PrintEntry 
)

Iterate over the hash and call PrintEntry.

Parameters:
Hashyour Hashlist structure
Transis called so you could for example print 'A:' if the next entries are like that. Must be aware to receive NULL in both pointers.
PrintEntryprint entry one by one
Returns:
the number of items printed

Definition at line 130 of file hash.c.

{
       int i;
       void *Previous;
       void *Next;
       const char* KeyStr;

       if (Hash == NULL)
              return 0;

       for (i=0; i < Hash->nLookupTableItems; i++) {
              if (i==0) {
                     Previous = NULL;
              }
              else {
                     if (Hash->LookupTable[i - 1] == NULL)
                            Previous = NULL;
                     else
                            Previous = Hash->Members[Hash->LookupTable[i-1]->Position]->Data;
              }
              if (Hash->LookupTable[i] == NULL) {
                     KeyStr = "";
                     Next = NULL;
              }
              else {
                     Next = Hash->Members[Hash->LookupTable[i]->Position]->Data;
                     KeyStr = Hash->LookupTable[i]->HashKey;
              }

              Trans(Previous, Next, i % 2);
              PrintEntry(KeyStr, Next, i % 2);
       }
       return i;
}