1 #ifndef _PBL_H_
2 #define _PBL_H_
3 /*
4  pbl.h - external include file of library
5 
6  Copyright (C) 2002 - 2007   Peter Graf
7 
8    This file is part of PBL - The Program Base Library.
9    PBL is free software.
10 
11     This library is free software; you can redistribute it and/or
12     modify it under the terms of the GNU Lesser General Public
13     License as published by the Free Software Foundation; either
14     version 2.1 of the License, or (at your option) any later version.
15 
16     This library is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     Lesser General Public License for more details.
20 
21     You should have received a copy of the GNU Lesser General Public
22     License along with this library; if not, write to the Free Software
23     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 
25    For more information on the Program Base Library or Peter Graf,
26    please see: http://www.mission-base.com/.
27 
28     $Log: pbl.h,v $
29     Revision 1.61  2010/08/29 15:29:31  peter
30     Added the heap functions.
31 
32 
33     Revision 1.59  2010/08/20 20:10:25  peter
34     Implemented the priority queue functions.
35 
36     Revision 1.51  2010/05/20 21:42:53  peter
37     Added pblSetReplace.
38 
39     Revision 1.50  2010/05/19 22:38:45  peter
40     Testing the map.
41 
42     Revision 1.49  2010/05/16 20:57:24  peter
43     Working on maps
44 
45     Revision 1.48  2010/05/15 16:26:10  peter
46     Exposing the map interface.
47 
48     Revision 1.47  2009/10/20 21:08:00  peter
49     Added the pblHtCurrentKey function.
50 
51     Revision 1.46  2009/03/08 20:56:50  peter
52     port to gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2.
53     Exposing the hash set and tree set interfaces.
54 
55 
56     Revision 1.28  2009/02/03 16:40:14  peter
57     PBL vesion 1.04, optimizations,
58     MAC OS X port, port to Microsoft Visual C++ 2008 Express Edition,
59     exposing the array list and the linked list interface
60 
61 
62     Revision 1.3  2004/04/04 13:12:53  peter
63     Added an ifdef vor Cygwin, proposed by Jari Aalto
64 
65     Revision 1.2  2002/09/12 20:47:18  peter
66     added the isam file handling to the library
67 
68     Revision 1.1  2002/09/05 13:44:12  peter
69     Initial revision
70 
71 */
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 #ifdef WIN32
78     #include <direct.h>
79     #include <io.h>
80 	#include <string.h>
81 #else
82 #ifndef __CYGWIN__
83     #include <sys/dirent.h>
84 #endif
85 #endif
86 
87 /*****************************************************************************/
88 /* #defines                                                                  */
89 /*****************************************************************************/
90 
91 
92 #ifdef _WIN32
93 
94 /*
95  * some functions have strange names on windows
96  */
97 #define strcasecmp   _stricmp
98 #define strncasecmp  _strnicmp
99 #define snprintf     _snprintf
100 #define close        _close
101 #define strdup       _strdup
102 #define open         _open
103 #define lseek        _lseek
104 #define write        _write
105 #define read         _read
106 #define unlink       _unlink
107 #define _CRT_SECURE_NO_WARNINGS 1
108 
109 #else
110 
111 #ifndef O_BINARY
112 #define O_BINARY     0
113 #endif
114 
115 #endif
116 
117 #define PBL_ERRSTR_LEN                    2048
118 
119 /** @name B: Files
120  *  List of important files of component
121  *  <P>
122  *  <B>FILES</B>
123  *  <UL>
124  *  <LI> <a href="../pbl.h">pbl.h</a> - The include file of the library
125  *  <LI> <a href="../pbl.c">pbl.c</a> - Source for the base functions
126  *  <LI> <a href="../pblList.c">pblList.c</a> - Source file for the
127  *                                              ArrayList and LinkedList functions
128  *  <LI> <a href="../pblListTest.c">pblListTest.c</a> - Source file for the
129  *                                              ArrayList and LinkedList function test frame
130  *  <LI> <a href="../pblhash.c">pblhash.c</a> - Source file for the
131  *                                              hash functions
132  *  <LI> <a href="../pblhttst.c">pblhttst.c</a> - Source file for the
133  *                                              hash function test frame
134  *  <LI> <a href="../pblkf.c">pblkf.c</a> - Source file for the key
135  *                                              file functions
136  *  <LI> <a href="../pblkftst.c">pblkftst.c</a> - Source file for the
137  *                                              key file handling test frame
138  *  <LI> <a href="../pblisam.c">pblisam.c</a> - Source file for the isam
139  *                                              file functions
140  *  <LI> <a href="../pbliftst.c">pbliftst.c</a> - Source file for the
141  *                                              isam file handling test frame
142  *  <LI> <a href="../makefile">makefile</a> - A Unix makefile for the
143  *                                              component
144  *  <LI> <a href="../pblhttstdeb.dsp">pblhttstdeb.dsp</a> - A Microsoft Visual
145  *                                              Studio 6.0 project file for
146  *                                              hash table debug
147  *  <LI> <a href="../pblkftstdeb.dsp">pblkftstdeb.dsp</a> - A Microsoft
148  *                                              Visual Studio 6.0 project file
149  *                                              for key file debug
150  *  <LI> <a href="../pbliftstdeb.dsp">pbliftstdeb.dsp</a> - A Microsoft Visual
151  *                                              Studio 6.0 project file for
152  *                                              isam file debug
153  *  <LI> <a href="../ISAM0001.TST">ISAM0001.TST</a> - A test case for the
154  *                                              isam file handling test frame
155  *  <LI> <a href="../ISAM0002.TST">ISAM0002.TST</a> - A test case for the
156  *                                              isam file handling test frame
157  *  <LI> <a href="../ISAM0003.TST">ISAM0003.TST</a> - A test case for the
158  *                                              isam file handling test frame
159  *  <LI> <a href="../ISAM0004.TST">ISAM0004.TST</a> - A test case for the
160  *                                              isam file handling test frame
161  *  <LI> <a href="../ISAM0005.TST">ISAM0005.TST</a> - A test case for the
162  *                                              isam file handling test frame
163  *  <LI> <a href="../ISAM0006.TST">ISAM0006.TST</a> - A test case for the
164  *                                              isam file handling test frame
165  *  <LI> <a href="../LINKEDLIST0001.TST">LINKEDLIST0001.TST</a> - A test case for the
166  *                                              LinkedList file handling test frame
167  *  <LI> <a href="../ARRAYLIST0001.TST">ARRAYLIST0001.TST</a> - A test case for the
168  *                                              ArrayList file handling test frame
169  *  <LI> <a href="../pbl.dxx">pbl.dxx</a> - The source for this document
170  *  </UL>
171  */
172 
173 #define PBL_FILE_LIST
174 
175 /** @name C: Error codes
176  *  error codes of the pbl library
177  *
178  *  @field PBL_ERROR_OUT_OF_MEMORY            Out of memory.
179  *  @field PBL_ERROR_EXISTS                   The record already exists.
180  *  @field PBL_ERROR_NOT_FOUND                Record not found.
181  *  @field PBL_ERROR_BAD_FILE                 File structure damaged.
182  *  @field PBL_ERROR_PARAM_MODE               Parameter mode is not valid.
183  *  @field PBL_ERROR_PARAM_KEY                Parameter key is not valid.
184  *  @field PBL_ERROR_PARAM_KEYLEN             Parameter keylen is not valid.
185  *  @field PBL_ERROR_PARAM_DATA               Parameter data is not valid.
186  *  @field PBL_ERROR_PARAM_DATALEN            Parameter datalen is not valid.
187  *  @field PBL_ERROR_PARAM_INDEX              Parameter index is not valid.
188  *  @field PBL_ERROR_PARAM_LIST               Parameter list is not valid.
189  *  @field PBL_ERROR_PARAM_COLLECTION         Parameter list is not valid.
190  *  @field PBL_ERROR_PARAM_ELEMENT            Parameter element is not valid.
191  *  @field PBL_ERROR_PARAM_SET                Parameter set is not valid.
192  *  @field PBL_ERROR_CREATE                   File system create error, see errno.
193  *  @field PBL_ERROR_OPEN                     File system open error, see errno.
194  *  @field PBL_ERROR_SEEK                     File system seek error, see errno.
195  *  @field PBL_ERROR_READ                     File system read error, see errno.
196  *  @field PBL_ERROR_WRITE                    File system write error, see errno.
197  *  @field PBL_ERROR_PROGRAM                  An internal error in the code, debug it!!
198  *  @field PBL_ERROR_NOFIT                    An internal condition forcing a block split.
199  *  @field PBL_ERROR_NOT_ALLOWED              File not open for update, operation not allowed.
200  *  @field PBL_ERROR_POSITION                 The current record is not positioned.
201  *  @field PBL_ERROR_OUT_OF_BOUNDS            Index out of range (index < 0 || index >= size()).
202  *  @field PBL_ERROR_CONCURRENT_MODIFICATION  A collection was modified concurrently to an iterator.
203  */
204 #define PBL_ERROR_BASE                    1000
205 
206 #define PBL_ERROR_OUT_OF_MEMORY           ( PBL_ERROR_BASE + 1 )
207 #define PBL_ERROR_EXISTS                  ( PBL_ERROR_BASE + 2 )
208 #define PBL_ERROR_NOT_FOUND               ( PBL_ERROR_BASE + 3 )
209 #define PBL_ERROR_BAD_FILE                ( PBL_ERROR_BASE + 4 )
210 #define PBL_ERROR_PARAM_MODE              ( PBL_ERROR_BASE + 5 )
211 #define PBL_ERROR_PARAM_KEY               ( PBL_ERROR_BASE + 6 )
212 #define PBL_ERROR_PARAM_KEYLEN            ( PBL_ERROR_BASE + 7 )
213 #define PBL_ERROR_PARAM_DATA              ( PBL_ERROR_BASE + 8 )
214 #define PBL_ERROR_PARAM_DATALEN           ( PBL_ERROR_BASE + 9 )
215 #define PBL_ERROR_PARAM_INDEX             ( PBL_ERROR_BASE + 10 )
216 #define PBL_ERROR_PARAM_LIST              ( PBL_ERROR_BASE + 11 )
217 #define PBL_ERROR_PARAM_COLLECTION        ( PBL_ERROR_BASE + 12 )
218 #define PBL_ERROR_PARAM_ELEMENT           ( PBL_ERROR_BASE + 13 )
219 #define PBL_ERROR_PARAM_SET               ( PBL_ERROR_BASE + 14 )
220 
221 #define PBL_ERROR_CREATE                  ( PBL_ERROR_BASE + 20 )
222 #define PBL_ERROR_OPEN                    ( PBL_ERROR_BASE + 21 )
223 #define PBL_ERROR_SEEK                    ( PBL_ERROR_BASE + 22 )
224 #define PBL_ERROR_READ                    ( PBL_ERROR_BASE + 23 )
225 #define PBL_ERROR_WRITE                   ( PBL_ERROR_BASE + 24 )
226 
227 #define PBL_ERROR_PROGRAM                 ( PBL_ERROR_BASE + 30 )
228 #define PBL_ERROR_NOFIT                   ( PBL_ERROR_BASE + 31 )
229 
230 #define PBL_ERROR_NOT_ALLOWED             ( PBL_ERROR_BASE + 40 )
231 #define PBL_ERROR_POSITION                ( PBL_ERROR_BASE + 41 )
232 #define PBL_ERROR_OUT_OF_BOUNDS           ( PBL_ERROR_BASE + 42 )
233 #define PBL_ERROR_CONCURRENT_MODIFICATION ( PBL_ERROR_BASE + 43 )
234 
235 
236 /** @name D: Definitions for Key File Parameters
237   * DEFINES FOR PARAMETER <B> mode </B> OF \Ref{pblKfFind}()
238   * @field PBLEQ                   any record that is equal
239   * @field PBLFI                   first record that is equal
240   * @field PBLLA                   last record that is equal
241   * @field PBLGE                   last equal or first that is greater
242   * @field PBLGT                   first that is greater
243   * @field PBLLE                   first equal or last that is smaller
244   * @field PBLLT                   last that is smaller
245   */
246 #define PBLEQ               1
247 #define PBLFI               2
248 #define PBLLA               3
249 #define PBLGE               4
250 #define PBLGT               5
251 #define PBLLE               6
252 #define PBLLT               7
253 
254 /** @name E: Definitions for ISAM Parameters
255   * DEFINES FOR PARAMETER <B> which </B> OF \Ref{pblIsamGet}()
256   * @field PBLTHIS                  get key and keylen of current record
257   * @field PBLNEXT                  get key and keylen of next record
258   * @field PBLPREV                  get key and keylen of previous record
259   * @field PBLFIRST                 get key and keylen of first record
260   * @field PBLLAST                  get key and keylen of last record
261  */
262 #define PBLTHIS             1
263 #define PBLNEXT             2
264 #define PBLPREV             3
265 #define PBLFIRST            4
266 #define PBLLAST             5
267 
268 /**
269  * the maximum length of a key of the key file component,
270  * @doc maximum length of a key, 255 for now
271  */
272 #define PBLKEYLENGTH      255
273 
274 /**
275  * maximum data length of data being stored on index blocks of key files,
276  * @doc maximum length of data stored with an item on the level 0 block, 1024
277  * @doc data that is longer is stored on data blocks.
278  */
279 #define PBLDATALENGTH    1024
280 
281 /*****************************************************************************/
282 /* macros                                                                    */
283 /*****************************************************************************/
284 
285 /*
286  * The PBL_MEMTRACE define can be used for debugging the library,
287  * if defined the library will log a line for all memory chunks
288  * that are allocated for more than 3 minutes into the file ./pblmemtrace.log
289  *
290  * This can be used to detect heap memory lost by the code.
291  * See also function pbl_memtrace_out in pbl.c
292  */
293 
294 /* #define PBL_MEMTRACE   */
295 #ifdef  PBL_MEMTRACE
296 
297 extern void pbl_memtrace_init( void );
298 extern void pbl_memtrace_delete( void * data );
299 extern void pbl_memtrace_out( int checktime );
300 
301 #define PBL_FREE( ptr ) if( ptr ){ pbl_memtrace_init(); pbl_memtrace_delete( ptr );\
302                                    free( ptr ); ptr = 0; }
303 
304 #else
305 
306 /**
307  * make free save against NULL pointers,
308  * @doc also the parameter ptr is set to NULL
309  */
310 #define PBL_FREE( ptr ) if( ptr ){ free( ptr ); ptr = 0; }
311 
312 #endif
313 
314 /**
315  * macros for linear list handling,
316  */
317 #define PBL_LIST_( Parameters )
318 
319 /**
320   * push an item to the beginning of a linear list
321   */
322 #define PBL_LIST_PUSH( HEAD, TAIL, ITEM, NEXT, PREV )\
323 {\
324     (ITEM)->PREV = 0;\
325     if(( (ITEM)->NEXT = (HEAD) ))\
326         { (ITEM)->NEXT->PREV = (ITEM); }\
327     else\
328         { (TAIL) = (ITEM); }\
329     (HEAD) = (ITEM);\
330 }
331 
332 /**
333   * append an item to the end of a linear list
334   */
335 #define PBL_LIST_APPEND( HEAD, TAIL, ITEM, NEXT, PREV )\
336                          PBL_LIST_PUSH( TAIL, HEAD, ITEM, PREV, NEXT )
337 
338 /**
339   * add an item before another item of a linear list
340   */
341 #define PBL_LIST_INSERT( HEAD, OTHER, ITEM, NEXT, PREV )\
342 {\
343     if(((ITEM)->PREV = (OTHER)->PREV))\
344         { (ITEM)->PREV->NEXT = (ITEM); }\
345     else\
346         { HEAD = (ITEM); }\
347     (ITEM)->NEXT = (OTHER);\
348     (OTHER)->PREV = (ITEM);\
349 }
350 
351 /**
352   * add an item after another item of a linear list
353   */
354 #define PBL_LIST_INSERT_AFTER( TAIL, OTHER, ITEM, NEXT, PREV )\
355                                PBL_LIST_INSERT( TAIL, OTHER, ITEM, PREV, NEXT )
356 
357 /**
358   * remove an item from a linear list
359   */
360 #define PBL_LIST_UNLINK( HEAD, TAIL, ITEM, NEXT, PREV )\
361 {\
362     if( (ITEM)->NEXT )\
363         { (ITEM)->NEXT->PREV = (ITEM)->PREV; }\
364     else\
365         { (TAIL) = (ITEM)->PREV; }\
366     if( (ITEM)->PREV )\
367         { (ITEM)->PREV->NEXT = (ITEM)->NEXT; }\
368     else\
369         { (HEAD) = (ITEM)->NEXT; }\
370 }
371 
372 /*
373  * SOME MACROS FOR KEY FILE READ FUNCTIONS
374  */
375 /**
376  * set the current record to the first record of the file
377  */
378 #define pblKfFirst( KF, K, L ) pblKfGetAbs( KF,  0, K, L )
379 
380 /**
381  * set the current record to the last record of the file
382  */
383 #define  pblKfLast( KF, K, L ) pblKfGetAbs( KF, -1, K, L )
384 
385 /**
386  * set the current record to the next record of the file
387  */
388 #define  pblKfNext( KF, K, L ) pblKfGetRel( KF,  1, K, L )
389 
390 /**
391  * set the current record to the previous record of the file
392  */
393 #define  pblKfPrev( KF, K, L ) pblKfGetRel( KF, -1, K, L )
394 
395 /**
396  * return the datalen of the current record
397  */
398 #define  pblKfThis( KF, K, L ) pblKfGetRel( KF,  0, K, L )
399 
400 /*
401  * Macros to allow to distinguish collection objects
402  */
403 #define PBL_LIST_IS_LIST( LIST ) (PBL_LIST_IS_ARRAY_LIST( LIST )\
404         || PBL_LIST_IS_LINKED_LIST( LIST ))
405 
406 #define PBL_LIST_IS_ARRAY_LIST( LIST )\
407     (LIST ? (((PblList*)LIST)->magic == PblArrayListMagic) : 0 )
408 
409 #define PBL_LIST_IS_LINKED_LIST( LIST )\
410     (LIST ? (((PblList*)LIST)->magic == PblLinkedListMagic) : 0 )
411 
412 #define PBL_SET_IS_SET( SET ) (PBL_SET_IS_HASH_SET( SET )\
413     || PBL_SET_IS_TREE_SET( SET ))
414 
415 #define PBL_SET_IS_HASH_SET( SET )\
416     (SET ? (((PblSet*)SET)->magic == PblHashSetMagic) : 0 )
417 
418 #define PBL_SET_IS_TREE_SET( SET )\
419     (SET ? (((PblSet*)SET)->magic == PblTreeSetMagic) : 0 )
420 
421 #define PBL_COLLECTION_IS_COLLECTION( COLL ) \
422         (PBL_LIST_IS_LIST( COLL ) || PBL_SET_IS_SET( COLL ))
423 
424 /*****************************************************************************/
425 /* typedefs                                                                  */
426 /*****************************************************************************/
427 
428 struct pblHashTable_s
429 {
430     char * magic;
431 };
432 
433 /**
434   * The hash table type the pblHt* functions are dealing with.
435   * @doc The details of the structure are hidden from the user.
436   */
437 typedef struct pblHashTable_s pblHashTable_t;
438 
439 struct pblKeyFile_s
440 {
441     char * magic;
442 };
443 
444 /**
445   * The key file type the pblKf* functions are dealing with.
446   * @doc The details of the structure are hidden from the user.
447   */
448 typedef struct pblKeyFile_s pblKeyFile_t;
449 
450 struct pblIsamFile_s
451 {
452     char * magic;
453 };
454 
455 /**
456   * The ISAM file type the pblIsam* functions are dealing with.
457   * @doc The details of the structure are hidden from the user.
458   */
459 typedef struct pblIsamFile_s pblIsamFile_t;
460 
461 /*
462  * The generic collection.
463  */
464 struct PblCollection_s
465 {
466     char * magic;         /* The magic string of collections                 */
467     int size;             /* The size of the collections                     */
468 
469     /* A user defined element compare function                               */
470     int (*compare)( const void * prev, const void * next );
471 
472     unsigned long changeCounter; /* Number of changes on the collections     */
473 
474 };
475 
476 /**
477  * The generic collection type.
478  */
479 typedef struct PblCollection_s PblCollection;
480 
481 /*
482  * An node type used in a tree set.
483  */
484 typedef struct PblTreeNode_s
485 {
486     void * element;                     /* The element the node points to  */
487 
488     struct PblTreeNode_s * prev;        /* The left node                   */
489     struct PblTreeNode_s * next;        /* The right node                  */
490 
491     struct PblTreeNode_s * parent;      /* The parent node                 */
492     int balance;                        /* AVL balance information of node */
493 
494 
495 } PblTreeNode;
496 
497 /**
498  * The generic set type.
499  */
500 typedef PblCollection PblSet;
501 
502 /*
503  * The hash set type.
504  */
505 typedef struct PblHashSet_s
506 {
507     PblSet genericSet;     /* The generic set definition of the hash set     */
508 
509     /* The array of all pointers hashed                                      */
510     unsigned char ** pointerArray;
511 
512     int capacity;          /* The capacity of the pointer array              */
513     int stepSize;          /* The step size used for collision resolution    */
514     double loadFactor;     /* The load factor of the hash set                */
515 
516     /* A user defined element hash value function                            */
517     int (*hashValue)( const void * element );
518 
519 } PblHashSet;
520 
521 /*
522  * The tree set type, actually an AVL tree with a parent node pointer
523  * allowing iteration from a node to its predecessor and successor
524  */
525 typedef struct PblTreeSet_s
526 {
527     PblSet genericSet;       /* The generic set definition of the tree set   */
528 
529     PblTreeNode * rootNode;  /* The root node of the AVL tree                */
530 
531 } PblTreeSet;
532 
533 /*
534  * An node type used in a linked list.
535  */
536 typedef struct PblLinkedNode_s
537 {
538     void * element;
539 
540     struct PblLinkedNode_s * prev;       /* The previous node in the list    */
541     struct PblLinkedNode_s * next;       /* The next node in the list        */
542 
543 } PblLinkedNode;
544 
545 /**
546  * The generic list type.
547  */
548 typedef PblCollection PblList;
549 
550 /*
551  * The linked list type.
552  */
553 typedef struct PblLinkedList_s
554 {
555     PblList genericList;  /* The generic list definition of the linked list  */
556 
557     PblLinkedNode * head;       /* The head of list of all nodes             */
558     PblLinkedNode * tail;       /* The tail of list of all nodes             */
559 
560 } PblLinkedList;
561 
562 /*
563  * The array list type.
564  */
565 typedef struct PblArrayList_s
566 {
567     PblList genericList;  /* The generic list definition of the array list   */
568 
569     /* The array of all pointers known                                       */
570     unsigned char ** pointerArray;
571 
572     int capacity;         /* The capacity of the pointer array               */
573 
574 } PblArrayList;
575 
576 /*
577  * The iterator struct.
578  */
579 struct PblIterator_s
580 {
581     char          * magic;         /* The magic string of iterators            */
582     unsigned long   changeCounter; /* The number of changes on the collection  */
583     PblCollection * collection;    /* The collection the iterator works on     */
584     int             index;         /* The current index of the iterator        */
585 
586     int lastIndexReturned;         /* Index of element that was returned last  */
587 
588     PblLinkedNode * current;       /* The current node in the linked list      */
589 
590     PblLinkedNode * prev;          /* The previous node in the linked  list    */
591     PblLinkedNode * next;          /* The next node in the linked  list        */
592 };
593 
594 /**
595  * The iterator type.
596  */
597 typedef struct PblIterator_s PblIterator;
598 
599 /*
600  * The map struct
601  */
602 struct PblMap_s
603 {
604     PblSet * entrySet;        /* The set containing the entries of the map   */
605 };
606 
607 /**
608  * The map type.
609  */
610 typedef struct PblMap_s PblMap;
611 
612 /*
613  * The map entry struct
614  */
615 struct PblMapEntry_s
616 {
617     int         tag;
618     size_t      keyLength;
619     size_t      valueLength;
620     char        buffer[];
621 };
622 
623 /**
624  * The map entry type.
625  */
626 typedef struct PblMapEntry_s PblMapEntry;
627 
628 /*
629  * The map key struct
630  */
631 struct PblMapKey_s
632 {
633     int         tag;
634     size_t      keyLength;
635     void    *   key;
636 };
637 
638 /**
639  * The map key type.
640  */
641 typedef struct PblMapKey_s PblMapKey;
642 
643 /**
644  * The heap.
645  */
646 #ifdef __cplusplus
647 typedef PblList PblHeap;
648 #else
649 typedef struct PblList PblHeap;
650 #endif
651 
652 /**
653  * The priority queue entry struct.
654  * The entry consists of the priority and of the payload.
655  */
656 struct PblPriorityQueueEntry_s
657 {
658     int         priority;
659     void    *   element;
660 };
661 
662 /**
663  * The priority queue entry.
664  */
665 typedef struct PblPriorityQueueEntry_s PblPriorityQueueEntry;
666 
667 /**
668  * The priority queue.
669  */
670 #ifdef __cplusplus
671 typedef PblList PblPriorityQueue;
672 #else
673 typedef struct PblList PblPriorityQueue;
674 #endif
675 
676 /*****************************************************************************/
677 /* variable declarations                                                     */
678 /*****************************************************************************/
679 /**
680   * Integer value used for returning error codes
681   */
682 extern int    pbl_errno;
683 
684 /**
685   * Character buffer used for returning error strings
686   */
687 extern char * pbl_errstr;
688 
689 /*
690  * "Magic" strings to distinguish between objects
691  */
692 extern char * PblHashSetMagic;
693 extern char * PblTreeSetMagic;
694 extern char * PblArrayListMagic;
695 extern char * PblLinkedListMagic;
696 extern char * PblIteratorMagic;
697 
698 /*****************************************************************************/
699 /* function declarations                                                     */
700 /*****************************************************************************/
701 extern void * pbl_malloc( char * tag, size_t size );
702 extern void * pbl_malloc0( char * tag, size_t size );
703 extern void * pbl_memdup( char * tag, void * data, size_t size );
704 extern void * pbl_strdup( char * tag, char * data );
705 extern void * pbl_mem2dup( char * tag, void * mem1, size_t len1,
706                            void * mem2, size_t len2 );
707 extern int    pbl_memcmplen( void * left, size_t llen,
708                              void * right, size_t rlen );
709 extern int    pbl_memcmp( void * left, size_t llen, void * right, size_t rlen );
710 extern size_t pbl_memlcpy( void * to, size_t tolen, void * from, size_t n );
711 
712 extern void   pbl_ShortToBuf( unsigned char * buf, int s );
713 extern int    pbl_BufToShort( unsigned char * buf );
714 extern void   pbl_LongToBuf( unsigned char * buf, long l );
715 extern long   pbl_BufToLong( unsigned char * buf );
716 extern int    pbl_LongToVarBuf( unsigned char * buffer, unsigned long value );
717 extern int    pbl_VarBufToLong( unsigned char * buffer, unsigned long * value );
718 extern int    pbl_LongSize( unsigned long value );
719 extern int    pbl_VarBufSize( unsigned char * buffer );
720 extern void   pbl_LongToHexString( unsigned char * buf, unsigned long l );
721 
722 extern int pblHtHashValue( const unsigned char * key, size_t keylen );
723 extern int pblHtHashValueOfString( const unsigned char * key );
724 
725 extern pblHashTable_t * pblHtCreate( void );
726 extern int    pblHtInsert  ( pblHashTable_t * h, void * key, size_t keylen,
727                              void * dataptr);
728 extern void * pblHtLookup  ( pblHashTable_t * h, void * key, size_t keylen );
729 extern void * pblHtFirst   ( pblHashTable_t * h );
730 extern void * pblHtNext    ( pblHashTable_t * h );
731 extern void * pblHtCurrent ( pblHashTable_t * h );
732 extern void * pblHtCurrentKey ( pblHashTable_t * h, size_t * keylen );
733 extern int    pblHtRemove  ( pblHashTable_t * h, void * key, size_t keylen );
734 extern int    pblHtDelete  ( pblHashTable_t * h );
735 
736 /*
737  * Functions on collections
738  */
739 extern int pblCollectionAggregate(
740     PblCollection * collection,  /** The collection to aggregate.                                 */
741     void * context,              /** The application context to pass to the aggregation function. */
742     int ( *aggregation )         /** The aggregation function called on every collection element. */
743         (
744             void * context,      /** The application context passed.                              */
745             int index,           /** The index of the element passed.                             */
746             void * element       /** The collection element to aggregate.                         */
747         )
748     );
749 
750 extern int pblCollectionContains(
751     PblCollection * collection, /** The collection to use            */
752     void * element              /** Element to look for              */
753     );
754 
755 extern PblList * pblCollectionConvertToArrayList( PblCollection * collection );
756 
757 extern PblSet * pblCollectionConvertToHashSet(
758 PblCollection * collection,  /** The collection to convert                            */
759 int ( *hashValue )           /** The hash value function for the new set, may be NULL */
760     (
761         const void* element  /** The element to get the hash value for                */
762     ));
763 
764 extern PblList * pblCollectionConvertToLinkedList( PblCollection * collection );
765 
766 extern PblSet * pblCollectionConvertToTreeSet( PblCollection * collection );
767 
768 extern int pblCollectionDefaultCompare(
769     const void *left,     /** left element for compare  */
770     const void *right     /** right element for compare */
771 );
772 
773 extern int pblCollectionElementCompare(
774 PblCollection * collection,    /** The collection to compare the elements for   */
775 void *left,
776 void *right
777 );
778 
779 extern int pblCollectionIsCollection(
780     void * object      /** The object to test */
781     );
782 
783 extern int pblCollectionStringCompareFunction(
784         const void * left,                /* left value for comparison  */
785         const void * right                /* right value for comparison */
786         );
787 
788 extern void * pblCollectionSetCompareFunction(
789 PblCollection * collection,  /** The collection to set compare function for   */
790 int ( *compare )             /** The compare function to set                  */
791     (
792         const void* prev,    /** "left" element for compare                   */
793         const void* next     /** "right" element for compare                  */
794     )
795 );
796 
797 /*
798  * FUNCTIONS ON ITERATORS
799  */
800 extern int pblIteratorAdd(
801         PblIterator * iterator, /** The iterator to add the element to */
802         void * element          /** Element to be added to this list   */
803         );
804 
805 
806 extern void pblIteratorFree(
807         PblIterator * iterator /** The iterator to free */
808         );
809 
810 extern int pblIteratorHasNext(
811         PblIterator * iterator /** The iterator to check the next element for */
812         );
813 
814 
815 extern int pblIteratorHasPrevious(
816         PblIterator * iterator /** The iterator to check the previous element for */
817         );
818 
819 extern int pblIteratorInit(
820 PblCollection * collection,    /** The collection to create the iterator for */
821 PblIterator   * iterator
822 );
823 
824 extern PblIterator * pblIteratorNew(
825 PblCollection * collection     /** The collection to create the iterator for */
826 );
827 
828 extern void * pblIteratorNext(
829         PblIterator * iterator /** The iterator to return the next element for */
830         );
831 
832 extern int pblIteratorNextIndex(
833         PblIterator * iterator /** The iterator to use */
834         );
835 
836 extern void * pblIteratorPrevious(
837         PblIterator * iterator /** The iterator to return the previous element for */
838         );
839 
840 extern int pblIteratorPreviousIndex(
841         PblIterator * iterator /** The iterator to use */
842         );
843 
844 extern int pblIteratorRemove(
845         PblIterator * iterator /** The iterator to remove the next element from */
846         );
847 
848 extern int pblIteratorReverseInit(
849         PblCollection * collection,          /** The collection to create the iterator for */
850         PblIterator   * iterator             /** The iterator to initialize                */
851         );
852 
853 extern PblIterator * pblIteratorReverseNew(
854 PblCollection * collection          /** The collection to create the iterator for */
855 );
856 
857 extern void * pblIteratorSet(
858         PblIterator * iterator, /** The iterator to replace the element of. */
859         void * element          /** Element with which to replace the last element returned by next or previous. */
860         );
861 
862 extern int pblIteratorSize(
863         PblIterator * iterator /** The iterator to use */
864         );
865 
866 /*
867  * FUNCTIONS ON LISTS
868  */
869 extern int pblListAdd(
870         PblList * list, /** The list to use                                */
871         void * element  /** Element to be appended to this list            */
872         );
873 
874 extern int pblListAddAll(
875         PblList * list,   /** The list to use                                */
876         void * collection /** The collection whose elements are to be added to this list. */
877         );
878 
879 extern int pblListAddAllAt(
880         PblList * list,   /** The list to use                                */
881         int index,        /** Index at which the element is to be inserted   */
882         void * collection /** The collection whose elements are to be added to this list. */
883         );
884 
885 extern int pblListAddAt(
886         PblList * list, /** The list to use                                */
887         int index,      /** Index at which the element is to be inserted   */
888         void * element  /** Element to be appended to this list            */
889         );
890 
891 extern int pblListAddFirst(
892         PblList * list, /** The list to add to              */
893         void * element  /** Element to be added to the list */
894         );
895 
896 extern int pblListAddLast(
897         PblList * list, /** The list to add to              */
898         void * element  /** Element to be added to the list */
899         );
900 
901 extern void pblListClear(
902         PblList * list  /** The list to clear */
903         );
904 
905 extern PblList * pblListClone(
906         PblList * list  /** The list to clone */
907         );
908 
909 extern PblList * pblListCloneRange(
910         PblList * list,   /** The list to use                             */
911         int fromIndex,    /** The index of first element to be cloned.    */
912         int toIndex       /** The index after last element to be cloned.  */
913         );
914 
915 extern int pblListContains(
916         PblList * list,           /** The list to use                   */
917         void * element            /** Element to look for               */
918         );
919 
920 extern int pblListContainsAll(
921         PblList * list,   /** The list to use */
922         void * collection /** The collection whose elements are to be added to this list. */
923         );
924 
925 extern int pblListDefaultCompare( const void *left, const void *right );
926 
927 extern void * pblListElement(
928         PblList * list   /** The list to use */
929         );
930 
931 extern int pblListEnsureCapacity(
932         PblList * list,  /** The list to use              */
933         int minCapacity  /** The desired minimum capacity */
934         );
935 
936 extern int pblListEquals(
937         PblList * list,   /** The list to compare with.                                  */
938         void * collection /** The collection to be compared for equality with this list. */
939         );
940 
941 extern void pblListFree(
942         PblList * list  /** The list to free */
943         );
944 
945 extern void * pblListGet(
946         PblList * list, /** The list to use                */
947         int index       /** Index of the element to return */
948         );
949 
950 extern int pblListGetCapacity(
951         PblList * list  /** The list to use  */
952         );
953 
954 extern void * pblListGetCompareFunction(
955         PblList * list  /** The list to get compare function for */
956         );
957 
958 extern void * pblListGetFirst(
959         PblList * list  /** The list to use */
960         );
961 
962 extern void * pblListGetLast(
963         PblList * list  /** The list to use */
964         );
965 
966 extern void * pblListHead(
967 PblList * list         /** The list to use  */
968 );
969 
970 extern int pblListIndexOf(
971         PblList * list,              /** The list to use     */
972         void * element               /** Element to look for */
973         );
974 
975 extern int pblListIsArrayList(
976         void * object   /** The object to test */
977         );
978 
979 extern int pblListIsEmpty(
980         PblList * list  /** The list to use */
981         );
982 
983 extern int pblListIsLinkedList(
984         void * object   /** The object to test */
985         );
986 
987 extern int pblListIsList(
988         void * object   /** The list to test */
989         );
990 
991 extern PblIterator * pblListIterator(
992         PblList * list  /** The list to create the iterator for */
993         );
994 
995 extern int pblListLastIndexOf(
996         PblList * list,           /** The list to use                   */
997         void * element            /** Element to look for               */
998         );
999 
1000 extern PblList * pblListNewArrayList( void );
1001 
1002 extern PblList * pblListNewLinkedList( void );
1003 
1004 extern int pblListOffer(
1005         PblList * list, /** The list to add to              */
1006         void * element  /** Element to be added to the list */
1007         );
1008 
1009 extern void * pblListPeek(
1010         PblList * list  /** The list to use */
1011         );
1012 
1013 extern void * pblListPoll(
1014         PblList * list  /** The list to use */
1015         );
1016 
1017 extern void * pblListPop(
1018         PblList * list  /** The list to use */
1019         );
1020 
1021 extern int pblListPush(
1022         PblList * list,   /** The list to append to               */
1023         void * element    /** Element to be appended to this list */
1024         );
1025 
1026 extern void * pblListRemove(
1027         PblList * list  /** The list to use */
1028         );
1029 
1030 extern int pblListRemoveAll(
1031         PblList * list,   /** The list to use */
1032         void * collection /** The collection whose elements are to be removed from this list. */
1033         );
1034 
1035 extern void * pblListRemoveAt(
1036         PblList * list, /** The list to use */
1037         int index       /** Index at which the element is to be removed */
1038         );
1039 
1040 extern int pblListRemoveElement(
1041         PblList * list,           /** The list to use   */
1042         void * element            /** Element to remove */
1043         );
1044 
1045 extern void * pblListRemoveFirst(
1046         PblList * list  /** The list to use */
1047         );
1048 
1049 extern void * pblListRemoveLast(
1050         PblList * list  /** The list to use */
1051         );
1052 
1053 extern int pblListRemoveRange(
1054         PblList * list, /** The list to use */
1055         int fromIndex,  /** The index of first element to be removed.*/
1056         int toIndex     /** The after last element to be removed.    */
1057         );
1058 
1059 extern int pblListRetainAll(
1060         PblList * list,   /** The list to use */
1061         void * collection /** The collection whose elements are to be removed from this list. */
1062         );
1063 
1064 extern void pblListReverse(
1065         PblList * list     /** The list to reverse */
1066         );
1067 
1068 extern PblIterator * pblListReverseIterator(
1069         PblList * list  /** The list to create the iterator for */
1070         );
1071 
1072 extern void * pblListSet(
1073         PblList * list, /** The list to use             */
1074         int index,      /** Index of element to replace */
1075         void * element  /** Element to be stored at the specified position */
1076         );
1077 
1078 extern void * pblListSetCompareFunction(
1079         PblList * list,    /** The list to set compare function for   */
1080         int ( *compare )   /** compare function to set                */
1081             (
1082                const void* prev, /** "left" element for compare  */
1083                const void* next /** "right" element for compare */
1084             )
1085         );
1086 
1087 extern void * pblListSetFirst(
1088         PblList * list,   /** The list to use                            */
1089         void    * element /** Element to be stored at the first position */
1090         );
1091 
1092 extern void * pblListSetLast(
1093         PblList * list,   /** The list to use                            */
1094         void    * element /** Element to be stored at the last position  */
1095         );
1096 
1097 
1098 extern int pblListSetSize(
1099         PblList * list, /** The list to set size for  */
1100         int size        /** The size to set           */
1101         );
1102 
1103 extern int pblListSize(
1104         PblList * list  /** The list to use */
1105         );
1106 
1107 extern int pblListSort(
1108         PblList * list,              /** The list to sort                       */
1109         int ( *compare )             /** Specific compare function to use       */
1110             (
1111                 const void* prev,    /** "left" element for compare             */
1112                 const void* next    /** "right" element for compare            */
1113             )
1114         );
1115 
1116 extern void * pblListTail(
1117 PblList * list         /** The list to use */
1118 );
1119 
1120 extern void ** pblListToArray(
1121         PblList * list  /** The list to use */
1122         );
1123 
1124 extern void * pblListTop(
1125         PblList * list   /** The list to use */
1126         );
1127 
1128 extern int pblListTrimToSize(
1129         PblList * list  /** The list to use*/
1130         );
1131 
1132 extern void * pblArrayListRemoveAt(
1133 PblArrayList * list,    /** The list to use                                */
1134 int index               /** Index at which the element is to be removed    */
1135 );
1136 
1137 /*
1138  * FUNCTIONS ON SETS
1139  */
1140 
1141 extern void ** pblHashElementFirst(
1142 PblHashSet * set
1143 );
1144 
1145 extern void ** pblHashElementNext(
1146 PblHashSet * set,
1147 void ** pointer
1148 );
1149 
1150 extern void ** pblHashElementLast(
1151 PblHashSet * set
1152 );
1153 
1154 extern void ** pblHashElementPrevious(
1155 PblHashSet * set,
1156 void ** pointer
1157 );
1158 
1159 extern int pblSetAdd(
1160         PblSet * set,   /** The set to use                                */
1161         void * element  /** Element to be appended to this set            */
1162         );
1163 
1164 extern int pblSetAddAll(
1165     PblSet * set,      /** The set to use                                */
1166     void * collection  /** The collection whose elements are to be added to this set. */
1167     );
1168 
1169 extern void * pblSetReplaceElement(
1170         PblSet * set,             /** The set to use                  */
1171         void * element            /** Element to look for             */
1172         );
1173 
1174 extern void pblSetClear(
1175         PblSet * set     /** The set to clear */
1176         );
1177 
1178 extern PblSet * pblSetClone(
1179         PblSet * set            /** The set to use                             */
1180         );
1181 
1182 extern PblSet * pblSetCloneRange(
1183 PblSet * set,              /** The set to use                               */
1184 int fromIndex,             /** The index of first element to be cloned.     */
1185 int toIndex                /** The index after last element to be cloned.   */
1186 );
1187 
1188 extern void * pblSetGetElement(
1189 PblSet * set,             /** The set to use                  */
1190 void * element            /** Element to look for             */
1191 );
1192 
1193 extern int pblSetContains(
1194     PblSet * set,             /** The set to use                  */
1195     void * element            /** Element to look for             */
1196     );
1197 
1198 extern int pblSetContainsAll(
1199     PblSet * set,      /** The set to use                                            */
1200     void * collection  /** The collection to be checked for containment in this set. */
1201     );
1202 
1203 extern int pblSetDefaultCompare(
1204     const void *left,     /** left element for compare  */
1205     const void *right     /** right element for compare */
1206 );
1207 
1208 extern int pblSetDefaultHashValue(
1209     const void *element     /** Element to calculate hash value for */
1210 );
1211 
1212 extern int pblSetStringHashValue(
1213     const void *string     /** The '\0' terminated string to calculate the hash value for */
1214     );
1215 
1216 extern PblSet * pblSetDifference(
1217 PblSet * setA,     /** The first set to build the difference from  */
1218 PblSet * setB      /** The second set to build the difference from */
1219 );
1220 
1221 extern void * pblSetElement(
1222 PblSet * set         /** The set to use  */
1223 );
1224 
1225 extern int pblSetEnsureCapacity(
1226     PblSet * set,   /** The set to use               */
1227     int minCapacity /** The desired minimum capacity */
1228     );
1229 
1230 extern int pblSetEquals(
1231     PblSet * set,     /** The set to compare with.                                  */
1232     void * collection /** The collection to be compared for equality with this set. */
1233     );
1234 
1235 extern void pblSetFree(
1236         PblSet * set    /** The set to free */
1237         );
1238 
1239 extern void * pblSetGet(
1240 PblSet * set,     /** The set to use                */
1241 int index         /** Index of the element to return */
1242 );
1243 
1244 extern int pblSetGetCapacity(
1245     PblSet * set          /** The set to use */
1246     );
1247 
1248 extern void * pblSetGetCompareFunction(
1249 PblSet * set         /** The set to get the compare function for   */
1250 );
1251 
1252 extern void * pblSetGetFirst(
1253 PblSet * set          /** The set to use */
1254 );
1255 
1256 extern void * pblSetGetHashValueFunction(
1257 PblSet * set         /** The set to get the hash value function for */
1258 );
1259 
1260 extern void * pblSetGetLast(
1261 PblSet * set         /** The set to use */
1262 );
1263 
1264 extern void * pblSetHead(
1265 PblSet * set         /** The set to use  */
1266 );
1267 
1268 extern int pblSetIndexOf(
1269 PblSet * set,      /** The set to use      */
1270 void * element     /** Element to look for  */
1271 );
1272 
1273 extern PblSet * pblSetIntersection(
1274 PblSet * setA,     /** The first set to intersect  */
1275 PblSet * setB      /** The second set to intersect */
1276 );
1277 
1278 extern int pblSetIsEmpty(
1279 PblSet * set      /** The set to test */
1280 );
1281 
1282 extern int pblSetIsHashSet(
1283 void * object           /** The object to test */
1284 );
1285 
1286 extern int pblSetIsSet(
1287 void * object      /** The object to test */
1288 );
1289 
1290 extern int pblSetIsSubset(
1291     PblSet * setA,     /** Superset to check  */
1292     PblSet * setB      /** Subset to check    */
1293 );
1294 
1295 extern int pblSetIsTreeSet(
1296 void * object            /** The object to test */
1297 );
1298 
1299 extern PblIterator * pblSetIterator(
1300 PblSet * set                 /** The set to create the iterator for */
1301 );
1302 
1303 extern int pblSetLastIndexOf(
1304     PblSet * set,      /** The set to use      */
1305     void * element     /** Element to look for  */
1306     );
1307 
1308 extern PblSet * pblSetNewHashSet( void );
1309 
1310 extern PblSet * pblSetNewTreeSet( void );
1311 
1312 extern void * pblSetPeek(
1313 PblSet * set      /** The set to use */
1314 );
1315 
1316 extern void * pblSetPoll(
1317 PblSet * set      /** The set to use                */
1318 );
1319 
1320 extern void * pblSetPop(
1321 PblSet * set     /** The set to use */
1322 );
1323 
1324 extern void pblSetPrint( FILE * outfile, PblSet * set );
1325 
1326 extern void * pblSetRemove(
1327 PblSet * set          /** The set to use */
1328 );
1329 
1330 extern int pblSetRemoveAll(
1331     PblSet * set,      /** The set to use                                                 */
1332     void * collection  /** The collection whose elements are to be removed from this set. */
1333     );
1334 
1335 extern void * pblSetRemoveAt(
1336 PblSet * set,         /** The set to use                                  */
1337 int index             /** The index at which the element is to be removed */
1338 );
1339 
1340 extern int pblSetRemoveElement(
1341 PblSet * set,            /** The set to use                        */
1342 void * element           /** Element to remove                     */
1343 );
1344 
1345 extern void * pblSetRemoveFirst(
1346 PblSet * set         /** The set to use */
1347 );
1348 
1349 extern void * pblSetRemoveLast(
1350 PblSet * set         /** The set to use */
1351 );
1352 
1353 extern int pblSetRetainAll(
1354     PblSet * set,           /** The set to use                           */
1355     void * collection       /** The elements to be retained in this set. */
1356     );
1357 
1358 extern PblIterator * pblSetReverseIterator(
1359 PblSet * set                 /** The set to create the iterator for */
1360 );
1361 
1362 extern void * pblSetSetCompareFunction(
1363 PblSet * set,                /** The set to set compare function for   */
1364 int ( *compare )             /** compare function to set               */
1365     (
1366         const void* prev,    /** "left" element for compare            */
1367         const void* next     /** "right" element for compare           */
1368     )
1369 );
1370 
1371 extern void * pblSetSetHashValueFunction(
1372 PblSet * set,                /** The set to set hash value function for */
1373 int ( *hashValue )           /** The hash value function to set         */
1374     (
1375         const void* element  /** The element to get the hash value for  */
1376     )
1377 );
1378 
1379 extern double pblSetSetLoadFactor(
1380     PblSet * set,                /** The set to set hash value function for */
1381     double loadFactor            /** The load factor to set                 */
1382     );
1383 
1384 extern int pblSetSize(
1385 PblSet * set   /** The set to use */
1386 );
1387 
1388 extern PblSet * pblSetSymmectricDifference(
1389 PblSet * setA,     /** The first set to use  */
1390 PblSet * setB      /** The second set to use */
1391 );
1392 
1393 extern void * pblSetTail(
1394 PblSet * set         /** The set to use */
1395 );
1396 
1397 extern void ** pblSetToArray(
1398 PblSet * set           /** The set to use */
1399 );
1400 
1401 extern void * pblSetTop(
1402 PblSet * set    /** The set to use */
1403 );
1404 
1405 extern int pblSetTrimToSize(
1406     PblSet * set         /** The set to use */
1407     );
1408 
1409 extern PblSet * pblSetUnion(
1410 PblSet * setA,     /** The first set to unite  */
1411 PblSet * setB      /** The second set to unite */
1412 );
1413 
1414 extern PblTreeNode * pblTreeNodeFirst(
1415 PblTreeNode * node                /** The node to use */
1416 );
1417 
1418 extern PblTreeNode * pblTreeNodeLast(
1419 PblTreeNode * node                /** The node to use */
1420 );
1421 
1422 extern PblTreeNode * pblTreeNodeNext(
1423 PblTreeNode * node                /** The node to use */
1424 );
1425 
1426 extern PblTreeNode * pblTreeNodePrevious(
1427 PblTreeNode * node                /** The node to use */
1428 );
1429 
1430 extern void pblTreeNodePrint( FILE * outfile, int level, PblTreeNode * node );
1431 
1432 /*
1433  * FUNCTIONS MAPS
1434  */
1435 
1436 extern int pblMapAdd( /*                                          */
1437     PblMap * map, /**                   The map to add to         */
1438     void * key, /**                     Key to add a mapping for  */
1439     size_t keyLength, /**               Length of the key         */
1440     void * value, /**                   Value of the new mapping  */
1441     size_t valueLength /**              Length of the value       */
1442     );
1443 
1444 extern int pblMapAddStrStr( /*                                    */
1445     PblMap * map, /**                   The map to add to         */
1446     char * key, /**                     Key to add a mapping for  */
1447     char * value /**                    Value of the new mapping  */
1448     );
1449 
1450 extern void pblMapClear( /*                                            */
1451     PblMap * map /**                                  The map to clear */
1452     );
1453 
1454 extern int pblMapContainsKey( /*                                                 */
1455     PblMap * map, /**             The map to check                               */
1456     void * key, /**               Key whose presence in this map is to be tested */
1457     size_t keyLength /**          Length of the key                              */
1458     );
1459 
1460 extern int pblMapContainsKeyStr( /*                                              */
1461     PblMap * map, /**             The map to check                               */
1462     char * key  /**               Key whose presence in this map is to be tested */
1463     );
1464 
1465 extern int pblMapContainsValue( /*                                               */
1466     PblMap * map, /**           The map to check                                 */
1467     void * value, /**           Value whose presence in this map is to be tested */
1468     size_t valueLength /**      Length of the value                              */
1469     );
1470 
1471 extern int pblMapContainsValueStr( /*                                            */
1472     PblMap * map, /**           The map to check                                 */
1473     char * value /**            Value whose presence in this map is to be tested */
1474     );
1475 
1476 extern void * pblMapEntryKey( /*                          */
1477         PblMapEntry * entry /**                 The entry */
1478         );
1479 
1480 extern size_t pblMapEntryKeyLength( /*                */
1481     PblMapEntry * entry /**                 The entry */
1482     );
1483 
1484 extern void * pblMapEntryValue( /*                        */
1485         PblMapEntry * entry /**                 The entry */
1486         );
1487 
1488 extern size_t pblMapEntryValueLength( /*                */
1489     PblMapEntry * entry /**                   The entry */
1490     );
1491 
1492 extern void pblMapFree( /*                                           */
1493     PblMap * map /**                                 The map to free */
1494     );
1495 
1496 extern void * pblMapGet( /*                                                       */
1497         PblMap * map, /**            The map to check                             */
1498         void * key, /**              Key whose associated value is to be returned */
1499         size_t keyLength, /**        Length of the key                            */
1500         size_t * valueLengthPtr /**  Out: Length of the value returned            */
1501         );
1502 
1503 extern void * pblMapGetStr( /*                                                    */
1504         PblMap * map, /**            The map to check                             */
1505         char * key, /**              Key whose associated value is to be returned */
1506         size_t * valueLengthPtr /**  Out: Length of the value returned            */
1507         );
1508 
1509 extern int pblMapIsEmpty( /*                            */
1510     PblMap * map /**                    The map to test */
1511     );
1512 
1513 extern PblIterator * pblMapIteratorNew( /*                  */
1514         PblMap * map /** The map to create the iterator for */
1515         );
1516 
1517 extern PblIterator * pblMapIteratorReverseNew( /*           */
1518         PblMap * map /** The map to create the iterator for */
1519         );
1520 
1521 extern PblMap * pblMapNewHashMap( void );
1522 
1523 extern PblMap * pblMapNewTreeMap( void );
1524 
1525 extern void * pblMapPut( /*                                                    */
1526         PblMap * map, /**                                    The map to add to */
1527         void * key, /**                               Key to add a mapping for */
1528         size_t keyLength, /**                                Length of the key */
1529         void * value, /**                             Value of the new mapping */
1530         size_t valueLength, /**                            Length of the value */
1531         size_t * valueLengthPtr /**          Out: Length of the value returned */
1532         );
1533 
1534 extern void * pblMapPutStrStr( /*                                              */
1535         PblMap * map, /**                                    The map to add to */
1536         char * key, /**                               Key to add a mapping for */
1537         char * value, /**                             Value of the new mapping */
1538         size_t * valueLengthPtr /**          Out: Length of the value returned */
1539         );
1540 
1541 extern int pblMapPutAll( /*                                         */
1542     PblMap * map, /**                The map to copy the entries to */
1543     PblMap * sourceMap /**         The map to copy the entries from */
1544     );
1545 
1546 extern void * pblMapRemove( /*                                              */
1547         PblMap * map, /**                            The map to remove from */
1548         void * key, /**                    Key whose association is removed */
1549         size_t keyLength, /**                             Length of the key */
1550         size_t * valueLengthPtr /**       Out: Length of the value returned */
1551         );
1552 
1553 extern void * pblMapRemoveStr( /*                                           */
1554         PblMap * map, /**                            The map to remove from */
1555         char * key, /**                    Key whose association is removed */
1556         size_t * valueLengthPtr /**       Out: Length of the value returned */
1557         );
1558 
1559 extern int pblMapSize( /*           */
1560     PblMap * map /** The map to use */
1561     );
1562 
1563 /*
1564  * FUNCTIONS ON HEAPS
1565  */
1566 extern PblHeap * pblHeapNew( void );
1567 
1568 extern void * pblHeapSetCompareFunction( /*                      */
1569         PblHeap * heap, /** The heap to set compare function for */
1570         int(*compare) /** The compare function to set            */
1571         ( /*                                                     */
1572         const void* prev, /** The "left" element for compare     */
1573         const void* next /** The "right" element for compare     */
1574         ) /*                                                     */
1575         );
1576 
1577 extern void pblHeapClear( /*             */
1578     PblHeap * heap /** The heap to clear */
1579     );
1580 
1581 extern void pblHeapFree( /*             */
1582     PblHeap * heap /** The heap to free */
1583     );
1584 
1585 extern int pblHeapEnsureCapacity( /*                 */
1586     PblHeap * heap, /** The heap to use              */
1587     int minCapacity /** The desired minimum capacity */
1588     );
1589 
1590 extern int pblHeapGetCapacity( /*      */
1591     PblHeap * heap /** The heap to use */
1592     );
1593 
1594 extern int pblHeapSize( /*             */
1595     PblHeap * heap /** The heap to use */
1596     );
1597 
1598 extern int pblHeapIsEmpty( /*          */
1599     PblHeap * heap /** The heap to use */
1600     );
1601 
1602 extern int pblHeapTrimToSize( /*       */
1603     PblHeap * heap /** The heap to use */
1604     );
1605 
1606 extern int pblHeapEnsureCondition( /*                     */
1607     PblHeap * heap, /** The heap to use                   */
1608     int index /** Index of element to ensure condtion for */
1609     );
1610 
1611 extern int pblHeapEnsureConditionFirst( /**/
1612     PblHeap * heap /** The heap to use    */
1613     );
1614 
1615 extern int pblHeapAddLast( /*                          */
1616     PblHeap * heap, /** The heap to use                */
1617     void * element /** Element to be added to the heap */
1618     );
1619 
1620 extern int pblHeapInsert( /*                              */
1621     PblHeap * heap, /** The heap to use                   */
1622     void * element /** Element to be inserted to the heap */
1623     );
1624 
1625 extern void * pblHeapRemoveLast( /*        */
1626         PblHeap * heap /** The heap to use */
1627         );
1628 
1629 extern void * pblHeapRemoveAt( /*                                     */
1630         PblHeap * heap, /** The heap to use                           */
1631         int index /** The index at which the element is to be removed */
1632         );
1633 
1634 extern void * pblHeapRemoveFirst( /*       */
1635         PblHeap * heap /** The heap to use */
1636         );
1637 
1638 extern void * pblHeapGet( /*                         */
1639         PblHeap * heap, /** The heap to use          */
1640         int index /** Index of the element to return */
1641         );
1642 
1643 extern void * pblHeapGetFirst( /*          */
1644         PblHeap * heap /** The heap to use */
1645         );
1646 
1647 extern void pblHeapConstruct( /*       */
1648     PblHeap * heap /** The heap to use */
1649     );
1650 
1651 extern PblIterator * pblHeapIterator( /*   */
1652         PblHeap * heap /** The heap to use */
1653         );
1654 
1655 extern int pblHeapJoin( /*                     */
1656     PblHeap * heap, /** The heap to join to    */
1657     PblHeap * other /** The other heap to join */
1658     );
1659 
1660 /*
1661  * FUNCTIONS ON PRIORITY QUEUES
1662  */
1663 extern PblPriorityQueue * pblPriorityQueueNew( void );
1664 
1665 extern void pblPriorityQueueClear( /*               */
1666     PblPriorityQueue * queue /** The queue to clear */
1667     );
1668 
1669 extern void pblPriorityQueueFree( /*               */
1670     PblPriorityQueue * queue /** The queue to free */
1671     );
1672 
1673 extern int pblPriorityQueueEnsureCapacity( /*        */
1674     PblPriorityQueue * queue, /** The queue to use   */
1675     int minCapacity /** The desired minimum capacity */
1676     );
1677 
1678 extern int pblPriorityQueueGetCapacity( /*        */
1679     PblPriorityQueue * queue /** The queue to use */
1680     );
1681 
1682 extern int pblPriorityQueueSize( /*               */
1683     PblPriorityQueue * queue /** The queue to use */
1684     );
1685 
1686 extern int pblPriorityQueueIsEmpty( /*            */
1687     PblPriorityQueue * queue /** The queue to use */
1688     );
1689 
1690 extern int pblPriorityQueueTrimToSize( /*         */
1691     PblPriorityQueue * queue /** The queue to use */
1692     );
1693 
1694 extern int pblPriorityQueueAddLast( /*                    */
1695     PblPriorityQueue * queue, /** The queue to use        */
1696     int priority, /** Priority of the element to be added */
1697     void * element /** Element to be added to the queue   */
1698     );
1699 
1700 extern int pblPriorityQueueInsert( /*                        */
1701     PblPriorityQueue * queue, /** The queue to use           */
1702     int priority, /** Priority of the element to be inserted */
1703     void * element /** Element to be inserted to the queue   */
1704     );
1705 
1706 extern void * pblPriorityQueueRemoveAt( /*                                        */
1707         PblPriorityQueue * queue, /** The queue to use                            */
1708         int index, /** The index at which the element is to be removed            */
1709         int * priority /** On return contains the priority of the element removed */
1710         );
1711 
1712 extern void * pblPriorityQueueRemoveLast( /*                                      */
1713         PblPriorityQueue * queue, /** The queue to use                            */
1714         int * priority /** On return contains the priority of the element removed */
1715         );
1716 
1717 extern void * pblPriorityQueueRemoveFirst( /*                                 */
1718     PblPriorityQueue * queue, /** The queue to use                            */
1719     int * priority /** On return contains the priority of the element removed */
1720     );
1721 
1722 extern void * pblPriorityQueueGet( /*                                     */
1723         PblPriorityQueue * queue, /** The queue to use                    */
1724         int index, /** Index of the element to return                     */
1725         int * priority /** On return contains the priority of the element */
1726         );
1727 
1728 extern void * pblPriorityQueueGetFirst( /*                                  */
1729     PblPriorityQueue * queue, /** The queue to use                          */
1730     int * priority /** On return contains the priority of the first element */
1731     );
1732 
1733 extern void pblPriorityQueueConstruct( /*         */
1734     PblPriorityQueue * queue /** The queue to use */
1735     );
1736 
1737 extern int pblPriorityQueueChangePriorityAt( /*                     */
1738     PblPriorityQueue * queue, /** The queue to use                  */
1739     int index, /** The index at which the priority is to be changed */
1740     int priority /** The new priority of the element                */
1741     );
1742 
1743 extern int pblPriorityQueueChangePriorityFirst( /*         */
1744     PblPriorityQueue * queue, /** The queue to use         */
1745     int priority /** The new priority of the first element */
1746     );
1747 
1748 extern PblIterator * pblPriorityQueueIterator( /*     */
1749         PblPriorityQueue * queue /** The queue to use */
1750         );
1751 
1752 extern int pblPriorityQueueJoin( /*                      */
1753     PblPriorityQueue * queue, /** The queue to join to   */
1754     PblPriorityQueue * other /** The other queue to join */
1755     );
1756 
1757 /*
1758  * FUNCTIONS ON KEY FILES
1759  */
1760 int                   pblKfInit  ( int nblocks );
1761 extern pblKeyFile_t * pblKfCreate( char * path, void * filesettag );
1762 extern pblKeyFile_t * pblKfOpen  ( char * path, int update, void * filesettag );
1763 extern int            pblKfClose ( pblKeyFile_t * k );
1764 extern int            pblKfFlush ( pblKeyFile_t * k );
1765 extern int            pblKfStartTransaction( pblKeyFile_t * k );
1766 extern int            pblKfCommit( pblKeyFile_t * k, int rollback );
1767 extern int            pblKfSavePosition( pblKeyFile_t * k );
1768 extern int            pblKfRestorePosition( pblKeyFile_t * k );
1769 
1770 extern void pblKfSetCompareFunction(
1771 pblKeyFile_t * k,             /** key file to set compare function for  */
1772 int ( *keycompare )           /** compare function to set               */
1773     (
1774                 void* prev,   /** "left" buffer for compare             */
1775                 size_t llen,  /** length of that buffer                 */
1776                 void* next,  /** "right" buffer for compare            */
1777                 size_t rlen   /** length of that buffer                 */
1778     )
1779 );
1780 
1781 /*
1782  * WRITE FUNCTIONS ON RECORDS, DELETE AND UPDATE WORK ON CURRENT RECORD
1783  */
1784 extern int pblKfInsert(
1785 pblKeyFile_t   * k,
1786 void           * key,
1787 size_t           keylen,
1788 void           * data,
1789 size_t           datalen
1790 );
1791 
1792 extern int pblKfDelete( pblKeyFile_t * k );
1793 
1794 extern int pblKfUpdate(
1795 pblKeyFile_t   * k,
1796 void           * data,
1797 size_t           datalen
1798 );
1799 
1800 /*
1801  * KEY FILE READ FUNCTIONS ON RECORDS
1802  */
1803 extern long pblKfFind(
1804 pblKeyFile_t   * k,
1805 int              mode,
1806 void           * skey,
1807 size_t           skeylen,
1808 void           * okey,
1809 size_t         * okeylen
1810 );
1811 
1812 extern long pblKfRead(
1813 pblKeyFile_t  * k,
1814 void          * data,
1815 long            datalen
1816 );
1817 
1818 /*
1819  * FUNCTIONS ACTUALLY ONLY TO BE USED THROUGH THE MAKROS DEFINED BELOW
1820  *
1821  * however, the functions work, but they are not very fast
1822  *
1823  * pblKfGetRel - positions relative to the current record to any other
1824  *               record of the file, interface is like pblKfNext
1825  *
1826  * pblKfGetAbs - positions absolute to the absindex 'th record of the file,
1827  *               -1L means last, interface is like pblKfFirst
1828  */
1829 extern long pblKfGetRel( pblKeyFile_t * k,
1830                          long           relindex,
1831                          void         * okey,
1832                          size_t       * okeylen);
1833 extern long pblKfGetAbs( pblKeyFile_t * k,
1834                          long           absindex,
1835                          void         * okey,
1836                          size_t       * okeylen);
1837 
1838 /*
1839  * FUNCTIONS ON ISAM FILES
1840  */
1841 extern int pblIsamClose( pblIsamFile_t * isamfile );
1842 extern int pblIsamFlush( pblIsamFile_t * isamfile );
1843 extern int pblIsamDelete( pblIsamFile_t * isamfile );
1844 
1845 extern pblIsamFile_t * pblIsamOpen(
1846 char        * path,
1847 int           update,
1848 void        * filesettag,
1849 int           nkeys,
1850 char       ** keyfilenames,
1851 int         * keydup
1852 );
1853 
1854 extern int pblIsamInsert(
1855 pblIsamFile_t * isamfile,
1856 void          * allkeys,
1857 size_t          allkeyslen,
1858 void          * data,
1859 size_t          datalen
1860 );
1861 
1862 extern int pblIsamFind(
1863 pblIsamFile_t  * isamfile,
1864 int              mode,
1865 int              index,
1866 void           * skey,
1867 size_t           skeylen,
1868 void           * okey
1869 );
1870 
1871 extern int pblIsamGet(
1872 pblIsamFile_t  * isamfile,
1873 int              which,
1874 int              index,
1875 void           * okey
1876 );
1877 
1878 extern int pblIsamReadKey(
1879 pblIsamFile_t  * isamfile,
1880 int              index,
1881 void           * okey
1882 );
1883 
1884 extern long pblIsamReadDatalen( pblIsamFile_t * isamfile );
1885 
1886 extern long pblIsamReadData(
1887 pblIsamFile_t * isamfile,
1888 void          * buffer,
1889 size_t          bufferlen
1890 );
1891 
1892 extern long pblIsamUpdateData(
1893 pblIsamFile_t * isamfile,
1894 void          * data,
1895 size_t          datalen
1896 );
1897 
1898 extern int pblIsamUpdateKey(
1899 pblIsamFile_t  * isamfile,
1900 int              index,
1901 void           * ukey,
1902 size_t           ukeylen
1903 );
1904 
1905 extern int pblIsamStartTransaction( int nfiles, pblIsamFile_t ** isamfiles );
1906 extern int pblIsamCommit( int nfiles, pblIsamFile_t ** isamfiles, int rollback);
1907 
1908 #ifdef __APPLE__ /* Mac OS X needs this */
1909 
1910 extern void * malloc( size_t size );
1911 extern void free( void *);
1912 
1913 #endif
1914 
1915 #ifdef __cplusplus
1916 }
1917 #endif
1918 
1919 #endif
1920 
1921