• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/programs/libcprops/heap.h

Go to the documentation of this file.
00001 #ifndef KBW_HEAP
00002 #define KBW_HEAP
00003 
00004 /** @{ */
00005 /**
00006  * @file
00007  *
00008  * cp_heap is a generic heap implementation based on libheap and contributed 
00009  * to cprops by Kyle Wheeler. The original copyright notice follows.
00010  * 
00011  * This file (the header file for a generic C heap implementation) is licensed
00012  * under the BSD license, and is copyrighted to Kyle Wheeler, 2003. Feel free
00013  * to distribute and use as you see fit, as long as this copyright notice stays
00014  * with the code.
00015  * 
00016  */
00017 
00018 #include "config.h"
00019 #include "common.h"
00020 #include "collection.h"
00021 
00022 #include <errno.h>
00023 
00024 __BEGIN_DECLS
00025 
00026 typedef CPROPS_DLL struct _heap
00027 {
00028     void **heap;
00029     unsigned int heap_height;
00030     unsigned int heap_end;
00031     unsigned int heap_length;
00032 
00033     int mode;
00034     cp_compare_fn comp;
00035     cp_copy_fn copy;
00036     cp_destructor_fn dtr;
00037 
00038     cp_mutex *lock;
00039     cp_thread txowner;
00040 } cp_heap;
00041 
00042 #if defined(DEBUG) || defined(__TRACE__) || defined(_HEAP_TRACE)
00043 CPROPS_DLL
00044 void heap_info(cp_heap *h);
00045 #endif
00046 
00047 /* default create functions - creates a synchronized heap. 
00048  *
00049  * note that in contrast to he original libheap function, the compare functions
00050  * follows strcmp semantics - ie returns < 0 if the first parameter is smaller 
00051  * than the second, zero on equality and greater than zero if the second 
00052  * parameter is smaller. 
00053  */
00054 CPROPS_DLL
00055 cp_heap *cp_heap_create(cp_compare_fn comp);
00056 
00057 CPROPS_DLL
00058 cp_heap *cp_heap_create_by_option(int mode, 
00059                                   int initial_size,
00060                                   cp_compare_fn comp, 
00061                                   cp_copy_fn copy, 
00062                                   cp_destructor_fn dtr);
00063 
00064 /* push an item */
00065 CPROPS_DLL
00066 int cp_heap_push(cp_heap *h, void *in);
00067 
00068 /* get the item at the top of the heap */
00069 CPROPS_DLL
00070 void *cp_heap_peek(cp_heap *h);
00071 
00072 /* remove the item at the top of the heap */
00073 CPROPS_DLL
00074 void *cp_heap_pop(cp_heap *h);
00075 
00076 /* contract the heap to the minimal size to accomodate current item count */
00077 CPROPS_DLL
00078 int cp_heap_contract(cp_heap *h);
00079 
00080 /* destroy the heap */
00081 CPROPS_DLL
00082 void cp_heap_destroy(cp_heap *h);
00083 
00084 /* return the number of items stored on the heap */
00085 CPROPS_DLL
00086 unsigned int cp_heap_count(cp_heap *h);
00087 
00088 /* return the maximal number of items that can be stored before another resize
00089  * is triggered 
00090  */
00091 CPROPS_DLL
00092 unsigned int cp_heap_size(cp_heap *h);
00093 
00094 #ifdef DEBUG
00095 CPROPS_DLL
00096 int cp_heap_verify(cp_heap *h);
00097 #endif
00098 
00099 /* run a callback on all stored elements */
00100 CPROPS_DLL
00101 void cp_heap_callback(cp_heap *h, cp_callback_fn cb, void *prm);
00102 
00103 /* lock the heap for a transaction, ie performing a sequence of jointly 
00104  * synchronized operations
00105  */
00106 CPROPS_DLL
00107 int cp_heap_lock(cp_heap *h);
00108 
00109 /* release a transaction lock */
00110 CPROPS_DLL
00111 int cp_heap_unlock(cp_heap *h);
00112 
00113 /* internal - transaction aware locking */
00114 CPROPS_DLL
00115 int cp_heap_txlock(cp_heap *h);
00116 
00117 /* internal - transaction aware unlock */
00118 CPROPS_DLL
00119 int cp_heap_txunlock(cp_heap *h);
00120 
00121 /* retrieve the current mode setting */
00122 CPROPS_DLL
00123 int cp_heap_get_mode(cp_heap *h);
00124 
00125 /* set the specified mode bits */
00126 CPROPS_DLL
00127 int cp_heap_set_mode(cp_heap *h, int mode);
00128 
00129 /* unset the specified mode bits */
00130 CPROPS_DLL
00131 int cp_heap_unset_mode(cp_heap *h, int mode);
00132 
00133 __END_DECLS
00134 
00135 /** @} */
00136 
00137 #endif

Generated on Fri Oct 22 2010 11:02:22 for SST by  doxygen 1.7.1