00001 00030 #ifndef _HEAP 00031 #define _HEAP 00032 00033 /*---------------------------------------------------------------------------*/ 00034 /* Nested includes */ 00035 /*---------------------------------------------------------------------------*/ 00036 #include "util.h" 00037 #undef MAX 00038 #undef MIN 00039 00040 /*---------------------------------------------------------------------------*/ 00041 /* Constant declarations */ 00042 /*---------------------------------------------------------------------------*/ 00043 00044 00045 /*---------------------------------------------------------------------------*/ 00046 /* Stucture declarations */ 00047 /*---------------------------------------------------------------------------*/ 00048 00049 00050 /*---------------------------------------------------------------------------*/ 00051 /* Type declarations */ 00052 /*---------------------------------------------------------------------------*/ 00053 00054 typedef struct HeapSlot HeapSlot_t; 00055 00056 typedef struct Heap Heap_t; 00057 00058 /*---------------------------------------------------------------------------*/ 00059 /* Variable declarations */ 00060 /*---------------------------------------------------------------------------*/ 00061 00062 00063 /*---------------------------------------------------------------------------*/ 00064 /* Macro declarations */ 00065 /*---------------------------------------------------------------------------*/ 00066 00074 #define Heap_HeapForEachItem( \ 00075 /* Heap_t * */ heap /* heap whose element should be enumerated */, \ 00076 /* int */ i /* local variable for iterator */, \ 00077 /* void * */ data /* heap item */ \ 00078 ) \ 00079 for((i) = 0; (((i) < (heap)->nitems) && (data = (heap)->slots[i].item)); \ 00080 (i)++) 00081 00082 00083 00086 /*---------------------------------------------------------------------------*/ 00087 /* Function prototypes */ 00088 /*---------------------------------------------------------------------------*/ 00089 00090 EXTERN Heap_t * Heap_HeapInit ARGS((int length)); 00091 EXTERN Heap_t * Heap_HeapInitCompare ARGS((int length, int (*compare)(const void *, const void *))); 00092 EXTERN void Heap_HeapFree ARGS((Heap_t *heap)); 00093 EXTERN int Heap_HeapInsert ARGS((Heap_t *heap, void *item, long key)); 00094 EXTERN int Heap_HeapInsertCompare ARGS((Heap_t *heap, void *item, long key)); 00095 EXTERN int Heap_HeapExtractMin ARGS((Heap_t *heap, void *item, long *key)); 00096 EXTERN int Heap_HeapCount ARGS((Heap_t *heap)); 00097 EXTERN Heap_t * Heap_HeapClone ARGS((Heap_t *source)); 00098 EXTERN int Heap_HeapTest ARGS((Heap_t *heap)); 00099 EXTERN int Heap_HeapTestCompare ARGS((Heap_t *heap)); 00100 EXTERN void Heap_HeapApplyForEachElement(Heap_t *heap, int (*compare)(const void *)); 00101 00102 00103 00106 #endif /* _HEAP */