* add wrapper to destruct nested hashes
[citadel.git] / libcitadel / lib / hash.c
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <string.h>
4 //dbg
5 #include <stdio.h>
6 #include "libcitadel.h"
7 #include "lookup3.h"
8
9 typedef struct Payload Payload;
10
11 struct Payload {
12         /**
13          * \brief Hash Payload storage Structure; filled in linear.
14          */
15         void *Data; /**< the Data belonging to this storage */
16         DeleteHashDataFunc Destructor; /**< if we want to destroy Data, do it with this function. */
17 };
18
19 struct HashKey {
20         /**
21          * \brief Hash key element; sorted by key
22          */
23         long Key;         /**< Numeric Hashkey comperator for hash sorting */
24         long Position;    /**< Pointer to a Payload struct in the Payload Aray */
25         char *HashKey;    /**< the Plaintext Hashkey */
26         long HKLen;       /**< length of the Plaintext Hashkey */
27         Payload *PL;      /**< pointer to our payload for sorting */
28 };
29
30 struct HashList {
31         /**
32          * \brief Hash structure; holds arrays of Hashkey and Payload. 
33          */
34         Payload **Members;     /**< Our Payload members. This fills up linear */
35         HashKey **LookupTable; /**< Hash Lookup table. Elements point to members, and are sorted by their hashvalue */
36         char **MyKeys;         /**< this keeps the members for a call of GetHashKeys */
37         HashFunc Algorithm;    /**< should we use an alternating algorithm to calc the hash values? */
38         long nMembersUsed;     /**< how many pointers inside of the array are used? */
39         long MemberSize;       /**< how big is Members and LookupTable? */
40         long tainted;          /**< if 0, we're hashed, else s.b. else sorted us in his own way. */
41         long uniq;             /**< are the keys going to be uniq? */
42 };
43
44 struct HashPos {
45         /**
46          * \brief Anonymous Hash Iterator Object. used for traversing the whole array from outside 
47          */
48         long Position;
49 };
50
51
52 /**
53  * \brief Iterate over the hash and call PrintEntry. 
54  * \param Hash your Hashlist structure
55  * \param Trans is called so you could for example print 'A:' if the next entries are like that.
56  *        Must be aware to receive NULL in both pointers.
57  * \param PrintEntry print entry one by one
58  * \returns the number of items printed
59  */
60 int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry)
61 {
62         int i;
63         void *Previous;
64         void *Next;
65         const char* KeyStr;
66
67         if (Hash == NULL)
68                 return 0;
69
70         for (i=0; i < Hash->nMembersUsed; i++) {
71                 if (i==0) {
72                         Previous = NULL;
73                 }
74                 else {
75                         if (Hash->LookupTable[i - 1] == NULL)
76                                 Previous = NULL;
77                         else
78                                 Previous = Hash->Members[Hash->LookupTable[i-1]->Position]->Data;
79                 }
80                 if (Hash->LookupTable[i] == NULL) {
81                         KeyStr = "";
82                         Next = NULL;
83                 }
84                 else {
85                         Next = Hash->Members[Hash->LookupTable[i]->Position]->Data;
86                         KeyStr = Hash->LookupTable[i]->HashKey;
87                 }
88
89                 Trans(Previous, Next, i % 2);
90                 PrintEntry(KeyStr, Next, i % 2);
91         }
92         return i;
93 }
94
95
96 /**
97  * \brief verify the contents of a hash list; here for debugging purposes.
98  * \param Hash your Hashlist structure
99  * \param First Functionpointer to allow you to print your payload
100  * \param Second Functionpointer to allow you to print your payload
101  * \returns 0
102  */
103 int dbg_PrintHash(HashList *Hash, PrintHashContent First, PrintHashContent Second)
104 {
105         const char *foo;
106         const char *bar;
107         const char *bla = "";
108         long key;
109         long i;
110
111         if (Hash == NULL)
112                 return 0;
113
114         if (Hash->MyKeys != NULL)
115                 free (Hash->MyKeys);
116
117         Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nMembersUsed);
118 #ifdef DEBUG
119         printf("----------------------------------\n");
120 #endif
121         for (i=0; i < Hash->nMembersUsed; i++) {
122                 
123                 if (Hash->LookupTable[i] == NULL)
124                 {
125                         foo = "";
126                         bar = "";
127                         key = 0;
128                 }
129                 else 
130                 {
131                         key = Hash->LookupTable[i]->Key;
132                         foo = Hash->LookupTable[i]->HashKey;
133                         if (First != NULL)
134                                 bar = First(Hash->Members[Hash->LookupTable[i]->Position]->Data);
135                         else 
136                                 bar = "";
137                         if (Second != NULL)
138                                 bla = Second(Hash->Members[Hash->LookupTable[i]->Position]->Data);
139                         else
140                                 bla = "";
141                 }
142 #ifdef DEBUG
143                 printf (" ---- Hashkey[%ld][%ld]: '%s' Value: '%s' ; %s\n", i, key, foo, bar, bla);
144 #endif
145         }
146 #ifdef DEBUG
147         printf("----------------------------------\n");
148 #endif
149         return 0;
150 }
151
152
153 /**
154  * \brief instanciate a new hashlist
155  * \returns the newly allocated list. 
156  */
157 HashList *NewHash(int Uniq, HashFunc F)
158 {
159         HashList *NewList;
160         NewList = malloc (sizeof(HashList));
161         memset(NewList, 0, sizeof(HashList));
162
163         NewList->Members = malloc(sizeof(Payload*) * 100);
164         memset(NewList->Members, 0, sizeof(Payload*) * 100);
165
166         NewList->LookupTable = malloc(sizeof(HashKey*) * 100);
167         memset(NewList->LookupTable, 0, sizeof(HashKey*) * 100);
168
169         NewList->MemberSize = 100;
170         NewList->tainted = 0;
171         NewList->uniq = Uniq;
172         NewList->Algorithm = F;
173
174         return NewList;
175 }
176
177 int GetCount(HashList *Hash)
178 {
179         if(Hash==NULL) return 0;
180         return Hash->nMembersUsed;
181 }
182
183
184 /**
185  * \brief private destructor for one hash element.
186  * Crashing? go one frame up and do 'print *FreeMe->LookupTable[i]'
187  * \param Data an element to free using the user provided destructor, or just plain free
188  */
189 static void DeleteHashPayload (Payload *Data)
190 {
191         /** do we have a destructor for our payload? */
192         if (Data->Destructor)
193                 Data->Destructor(Data->Data);
194         else
195                 free(Data->Data);
196 }
197
198 /**
199  * \brief Destructor for nested hashes
200  */
201 void HDeleteHash(void *vHash)
202 {
203         HashList *FreeMe = (HashList*)vHash;
204         DeleteHash(&FreeMe);
205 }
206
207 /**
208  * \brief destroy a hashlist and all of its members
209  * Crashing? do 'print *FreeMe->LookupTable[i]'
210  * \param Hash Hash to destroy. Is NULL'ed so you are shure its done.
211  */
212 void DeleteHash(HashList **Hash)
213 {
214         int i;
215         HashList *FreeMe;
216
217         FreeMe = *Hash;
218         if (FreeMe == NULL)
219                 return;
220         for (i=0; i < FreeMe->nMembersUsed; i++)
221         {
222                 /** get rid of our payload */
223                 if (FreeMe->Members[i] != NULL)
224                 {
225                         DeleteHashPayload(FreeMe->Members[i]);
226                         free(FreeMe->Members[i]);
227                 }
228                 /** delete our hashing data */
229                 if (FreeMe->LookupTable[i] != NULL)
230                 {
231                         free(FreeMe->LookupTable[i]->HashKey);
232                         free(FreeMe->LookupTable[i]);
233                 }
234         }
235         /** now, free our arrays... */
236         free(FreeMe->LookupTable);
237         free(FreeMe->Members);
238         /** did s.b. want an array of our keys? free them. */
239         if (FreeMe->MyKeys != NULL)
240                 free(FreeMe->MyKeys);
241         /** buye bye cruel world. */    
242         free (FreeMe);
243         *Hash = NULL;
244 }
245
246 /**
247  * \brief Private function to increase the hash size.
248  * \param Hash the Hasharray to increase
249  */
250 static void IncreaseHashSize(HashList *Hash)
251 {
252         /* Ok, Our space is used up. Double the available space. */
253         Payload **NewPayloadArea;
254         HashKey **NewTable;
255         
256         if (Hash == NULL)
257                 return ;
258
259         /** double our payload area */
260         NewPayloadArea = (Payload**) malloc(sizeof(Payload*) * Hash->MemberSize * 2);
261         memset(&NewPayloadArea[Hash->MemberSize], 0, sizeof(Payload*) * Hash->MemberSize);
262         memcpy(NewPayloadArea, Hash->Members, sizeof(Payload*) * Hash->MemberSize);
263         free(Hash->Members);
264         Hash->Members = NewPayloadArea;
265         
266         /** double our hashtable area */
267         NewTable = malloc(sizeof(HashKey*) * Hash->MemberSize * 2);
268         memset(&NewTable[Hash->MemberSize], 0, sizeof(HashKey*) * Hash->MemberSize);
269         memcpy(NewTable, Hash->LookupTable, sizeof(HashKey*) * Hash->MemberSize);
270         free(Hash->LookupTable);
271         Hash->LookupTable = NewTable;
272         
273         Hash->MemberSize *= 2;
274 }
275
276
277 /**
278  * \brief private function to add a new item to / replace an existing in -  the hashlist
279  * if the hash list is full, its re-alloced with double size.
280  * \parame Hash our hashlist to manipulate
281  * \param HashPos where should we insert / replace?
282  * \param HashKeyStr the Hash-String
283  * \param HKLen length of HashKeyStr
284  * \param Data your Payload to add
285  * \param Destructor Functionpointer to free Data. if NULL, default free() is used.
286  */
287 static void InsertHashItem(HashList *Hash, 
288                            long HashPos, 
289                            long HashBinKey, 
290                            const char *HashKeyStr, 
291                            long HKLen, 
292                            void *Data,
293                            DeleteHashDataFunc Destructor)
294 {
295         Payload *NewPayloadItem;
296         HashKey *NewHashKey;
297
298         if (Hash == NULL)
299                 return;
300
301         if (Hash->nMembersUsed >= Hash->MemberSize)
302                 IncreaseHashSize (Hash);
303
304         /** Arrange the payload */
305         NewPayloadItem = (Payload*) malloc (sizeof(Payload));
306         NewPayloadItem->Data = Data;
307         NewPayloadItem->Destructor = Destructor;
308         /** Arrange the hashkey */
309         NewHashKey = (HashKey*) malloc (sizeof(HashKey));
310         NewHashKey->HashKey = (char *) malloc (HKLen + 1);
311         NewHashKey->HKLen = HKLen;
312         memcpy (NewHashKey->HashKey, HashKeyStr, HKLen + 1);
313         NewHashKey->Key = HashBinKey;
314         NewHashKey->PL = NewPayloadItem;
315         /** our payload is queued at the end... */
316         NewHashKey->Position = Hash->nMembersUsed;
317         /** but if we should be sorted into a specific place... */
318         if ((Hash->nMembersUsed != 0) && 
319             (HashPos != Hash->nMembersUsed) ) {
320                 long ItemsAfter;
321
322                 ItemsAfter = Hash->nMembersUsed - HashPos;
323                 /** make space were we can fill us in */
324                 if (ItemsAfter > 0)
325                 {
326                         memmove(&Hash->LookupTable[HashPos + 1],
327                                 &Hash->LookupTable[HashPos],
328                                 ItemsAfter * sizeof(HashKey*));
329                 } 
330         }
331         
332         Hash->Members[Hash->nMembersUsed] = NewPayloadItem;
333         Hash->LookupTable[HashPos] = NewHashKey;
334         Hash->nMembersUsed++;
335 }
336
337 /**
338  * \brief if the user has tainted the hash, but wants to insert / search items by their key
339  *  we need to search linear through the array. You have been warned that this will take more time!
340  * \param Hash Our Hash to manipulate
341  * \param HashBinKey the Hash-Number to lookup. 
342  * \returns the position (most closely) matching HashBinKey (-> Caller needs to compare! )
343  */
344 static long FindInTaintedHash(HashList *Hash, long HashBinKey)
345 {
346         long SearchPos;
347
348         if (Hash == NULL)
349                 return 0;
350
351         for (SearchPos = 0; SearchPos < Hash->nMembersUsed; SearchPos ++) {
352                 if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
353                         return SearchPos;
354                 }
355         }
356         return SearchPos;
357 }
358
359 /**
360  * \brief Private function to lookup the Item / the closest position to put it in
361  * \param Hash Our Hash to manipulate
362  * \param HashBinKey the Hash-Number to lookup. 
363  * \returns the position (most closely) matching HashBinKey (-> Caller needs to compare! )
364  */
365 static long FindInHash(HashList *Hash, long HashBinKey)
366 {
367         long SearchPos;
368         long StepWidth;
369
370         if (Hash == NULL)
371                 return 0;
372
373         if (Hash->tainted)
374                 return FindInTaintedHash(Hash, HashBinKey);
375
376         SearchPos = Hash->nMembersUsed / 2;
377         StepWidth = SearchPos / 2;
378         while ((SearchPos > 0) && 
379                (SearchPos < Hash->nMembersUsed)) 
380         {
381                 /** Did we find it? */
382                 if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
383                         return SearchPos;
384                 }
385                 /** are we Aproximating in big steps? */
386                 if (StepWidth > 1){
387                         if (Hash->LookupTable[SearchPos]->Key > HashBinKey)
388                                 SearchPos -= StepWidth;
389                         else
390                                 SearchPos += StepWidth;
391                         StepWidth /= 2;                 
392                 }
393                 else { /** We are right next to our target, within 4 positions */
394                         if (Hash->LookupTable[SearchPos]->Key > HashBinKey) {
395                                 if ((SearchPos > 0) && 
396                                     (Hash->LookupTable[SearchPos - 1]->Key < HashBinKey))
397                                         return SearchPos;
398                                 SearchPos --;
399                         }
400                         else {
401                                 if ((SearchPos + 1 < Hash->nMembersUsed) && 
402                                     (Hash->LookupTable[SearchPos + 1]->Key > HashBinKey))
403                                         return SearchPos;
404                                 SearchPos ++;
405                         }
406                         StepWidth--;
407                 }
408         }
409         return SearchPos;
410 }
411
412 /**
413  * \brief private abstract wrapper around the hashing algorithm
414  * \param HKey the hash string
415  * \param HKLen length of HKey
416  * \returns the calculated hash value
417  */
418 inline static long CalcHashKey (HashList *Hash, const char *HKey, long HKLen)
419 {
420         if (Hash == NULL)
421                 return 0;
422
423         if (Hash->Algorithm == NULL)
424                 return hashlittle(HKey, HKLen, 9283457);
425         else
426                 return Hash->Algorithm(HKey, HKLen);
427 }
428
429
430 /**
431  * \brief Add a new / Replace an existing item in the Hash
432  * \param HashList the list to manipulate
433  * \param HKey the hash-string to store Data under
434  * \param HKeyLen Length of HKey
435  * \param Data the payload you want to associate with HKey
436  * \param DeleteIt if not free() should be used to delete Data set to NULL, else DeleteIt is used.
437  */
438 void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt)
439 {
440         long HashBinKey;
441         long HashAt;
442
443         if (Hash == NULL)
444                 return;
445
446         /** first, find out were we could fit in... */
447         HashBinKey = CalcHashKey(Hash, HKey, HKLen);
448         HashAt = FindInHash(Hash, HashBinKey);
449
450         if (HashAt >= Hash->MemberSize)
451                 IncreaseHashSize (Hash);
452
453         /** oh, we're brand new... */
454         if (Hash->LookupTable[HashAt] == NULL) {
455                 InsertHashItem(Hash, HashAt, HashBinKey, HKey, HKLen, Data, DeleteIt);
456         }/** Insert After? */
457         else if (Hash->LookupTable[HashAt]->Key > HashBinKey) {
458                 InsertHashItem(Hash, HashAt, HashBinKey, HKey, HKLen, Data, DeleteIt);
459         }/** Insert before? */
460         else if (Hash->LookupTable[HashAt]->Key < HashBinKey) {
461                 InsertHashItem(Hash, HashAt + 1, HashBinKey, HKey, HKLen, Data, DeleteIt);
462         }
463         else { /** Ok, we have a colision. replace it. */
464                 if (Hash->uniq) {
465                         long PayloadPos;
466                         
467                         PayloadPos = Hash->LookupTable[HashAt]->Position;
468                         DeleteHashPayload(Hash->Members[PayloadPos]);
469                         Hash->Members[PayloadPos]->Data = Data;
470                         Hash->Members[PayloadPos]->Destructor = DeleteIt;
471                 }
472                 else {
473                         InsertHashItem(Hash, HashAt + 1, HashBinKey, HKey, HKLen, Data, DeleteIt);
474                 }
475         }
476 }
477
478 /**
479  * \brief Lookup the Data associated with HKey
480  * \param Hash the Hashlist to search in
481  * \param HKey the hashkey to look up
482  * \param HKLen length of HKey
483  * \param Data returns the Data associated with HKey
484  * \returns 0 if not found, 1 if.
485  */
486 int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data)
487 {
488         long HashBinKey;
489         long HashAt;
490
491         if (Hash == NULL)
492                 return 0;
493
494         if (HKLen <= 0) {
495                 *Data = NULL;
496                 return  0;
497         }
498         /** first, find out were we could be... */
499         HashBinKey = CalcHashKey(Hash, HKey, HKLen);
500         HashAt = FindInHash(Hash, HashBinKey);
501         if ((HashAt < 0) || /**< Not found at the lower edge? */
502             (HashAt >= Hash->nMembersUsed) || /**< Not found at the upper edge? */
503             (Hash->LookupTable[HashAt]->Key != HashBinKey)) { /**< somewhere inbetween but no match? */
504                 *Data = NULL;
505                 return 0;
506         }
507         else { /** GOTCHA! */
508                 long MemberPosition;
509
510                 MemberPosition = Hash->LookupTable[HashAt]->Position;
511                 *Data = Hash->Members[MemberPosition]->Data;
512                 return 1;
513         }
514 }
515
516 /* TODO? */
517 int GetKey(HashList *Hash, char *HKey, long HKLen, void **Payload)
518 {
519         return 0;
520 }
521
522 /**
523  * \brief get the Keys present in this hash, simila to array_keys() in PHP
524  *  Attention: List remains to Hash! don't modify or free it!
525  * \param Hash Your Hashlist to extract the keys from
526  * \param List returns the list of hashkeys stored in Hash
527  */
528 int GetHashKeys(HashList *Hash, char ***List)
529 {
530         long i;
531         if (Hash == NULL)
532                 return 0;
533         if (Hash->MyKeys != NULL)
534                 free (Hash->MyKeys);
535
536         Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nMembersUsed);
537         for (i=0; i < Hash->nMembersUsed; i++) {
538         
539                 Hash->MyKeys[i] = Hash->LookupTable[i]->HashKey;
540         }
541         *List = (char**)Hash->MyKeys;
542         return Hash->nMembersUsed;
543 }
544
545 /**
546  * \brief creates a hash-linear iterator object
547  * \returns the hash iterator
548  */
549 HashPos *GetNewHashPos(void)
550 {
551         HashPos *Ret;
552         
553         Ret = (HashPos*)malloc(sizeof(HashPos));
554         Ret->Position = 0;
555         return Ret;
556 }
557
558 /**
559  * \brief frees a linear hash iterator
560  */
561 void DeleteHashPos(HashPos **DelMe)
562 {
563         if (*DelMe != NULL)
564         {
565                 free(*DelMe);
566                 *DelMe = NULL;
567         }
568 }
569
570
571 /**
572  * \brief Get the data located where HashPos Iterator points at, and Move HashPos one forward
573  * \param Hash your Hashlist to follow
574  * \param HKLen returns Length of Hashkey Returned
575  * \param HashKey returns the Hashkey corrosponding to HashPos
576  * \param Data returns the Data found at HashPos
577  * \returns whether the item was found or not.
578  */
579 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data)
580 {
581         long PayloadPos;
582
583         if ((Hash == NULL) || (Hash->nMembersUsed <= At->Position))
584                 return 0;
585         *HKLen = Hash->LookupTable[At->Position]->HKLen;
586         *HashKey = Hash->LookupTable[At->Position]->HashKey;
587         PayloadPos = Hash->LookupTable[At->Position]->Position;
588         *Data = Hash->Members[PayloadPos]->Data;
589         At->Position++;
590         return 1;
591 }
592
593 /**
594  * \brief sorting function for sorting the Hash alphabeticaly by their strings
595  * \param Key1 first item
596  * \param Key2 second item
597  */
598 static int SortByKeys(const void *Key1, const void* Key2)
599 {
600         HashKey *HKey1, *HKey2;
601         HKey1 = *(HashKey**) Key1;
602         HKey2 = *(HashKey**) Key2;
603
604         return strcasecmp(HKey1->HashKey, HKey2->HashKey);
605 }
606
607 /**
608  * \brief sorting function for sorting the Hash alphabeticaly reverse by their strings
609  * \param Key1 first item
610  * \param Key2 second item
611  */
612 static int SortByKeysRev(const void *Key1, const void* Key2)
613 {
614         HashKey *HKey1, *HKey2;
615         HKey1 = *(HashKey**) Key1;
616         HKey2 = *(HashKey**) Key2;
617
618         return strcasecmp(HKey2->HashKey, HKey1->HashKey);
619 }
620
621 /**
622  * \brief sorting function to regain hash-sequence and revert tainted status
623  * \param Key1 first item
624  * \param Key2 second item
625  */
626 static int SortByHashKeys(const void *Key1, const void* Key2)
627 {
628         HashKey *HKey1, *HKey2;
629         HKey1 = *(HashKey**) Key1;
630         HKey2 = *(HashKey**) Key2;
631
632         return HKey1->Key > HKey2->Key;
633 }
634
635
636 /**
637  * \brief sort the hash alphabeticaly by their keys.
638  * Caution: This taints the hashlist, so accessing it later 
639  * will be significantly slower! You can un-taint it by SortByHashKeyStr
640  * \param Hash the list to sort
641  * \param Order 0/1 Forward/Backward
642  */
643 void SortByHashKey(HashList *Hash, int Order)
644 {
645         if (Hash->nMembersUsed < 2)
646                 return;
647         qsort(Hash->LookupTable, Hash->nMembersUsed, sizeof(HashKey*), 
648               (Order)?SortByKeys:SortByKeysRev);
649         Hash->tainted = 1;
650 }
651
652 /**
653  * \brief sort the hash by their keys (so it regains untainted state).
654  * this will result in the sequence the hashing allgorithm produces it by default.
655  * \param Hash the list to sort
656  */
657 void SortByHashKeyStr(HashList *Hash)
658 {
659         Hash->tainted = 0;
660         if (Hash->nMembersUsed < 2)
661                 return;
662         qsort(Hash->LookupTable, Hash->nMembersUsed, sizeof(HashKey*), SortByHashKeys);
663 }
664
665
666 /**
667  * \brief gives user sort routines access to the hash payload
668  * \param Searchentry to retrieve Data to
669  * \returns Data belonging to HashVoid
670  */
671 const void *GetSearchPayload(const void *HashVoid)
672 {
673         return (*(HashKey**)HashVoid)->PL->Data;
674 }
675
676 /**
677  * \brief sort the hash by your sort function. see the following sample.
678  * this will result in the sequence the hashing allgorithm produces it by default.
679  * \param Hash the list to sort
680  * \param SortBy Sortfunction; see below how to implement this
681  */
682 void SortByPayload(HashList *Hash, CompareFunc SortBy)
683 {
684         if (Hash->nMembersUsed < 2)
685                 return;
686         qsort(Hash->LookupTable, Hash->nMembersUsed, sizeof(HashKey*), SortBy);
687         Hash->tainted = 1;
688 }
689
690
691
692
693 /**
694  * given you've put char * into your hash as a payload, a sort function might
695  * look like this:
696  * int SortByChar(const void* First, const void* Second)
697  * {
698  *      char *a, *b;
699  *      a = (char*) GetSearchPayload(First);
700  *      b = (char*) GetSearchPayload(Second);
701  *      return strcmp (a, b);
702  * }
703  */
704
705
706 /*
707  * Generic function to free a pointer.  This can be used as a callback with the
708  * hash table, even on systems where free() is defined as a macro or has had other
709  * horrible things done to it.
710  */
711 void generic_free_handler(void *ptr) {
712         free(ptr);
713 }
714
715
716