00001 /* 00002 00003 Copyright (c) 2005-2008, Simon Howard 00004 00005 Permission to use, copy, modify, and/or distribute this software 00006 for any purpose with or without fee is hereby granted, provided 00007 that the above copyright notice and this permission notice appear 00008 in all copies. 00009 00010 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 00011 WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 00012 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 00013 AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 00014 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00015 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00016 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 00017 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00018 00019 */ 00020 00038 #ifndef ALGORITHM_BINARY_HEAP_H 00039 #define ALGORITHM_BINARY_HEAP_H 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00053 typedef enum { 00056 BINARY_HEAP_TYPE_MIN, 00057 00060 BINARY_HEAP_TYPE_MAX 00061 } BinaryHeapType; 00062 00067 typedef void *BinaryHeapValue; 00068 00073 #define BINARY_HEAP_NULL ((void *) 0) 00074 00085 typedef int (*BinaryHeapCompareFunc)(BinaryHeapValue value1, 00086 BinaryHeapValue value2); 00087 00092 typedef struct _BinaryHeap BinaryHeap; 00093 00104 BinaryHeap *binary_heap_new(BinaryHeapType heap_type, 00105 BinaryHeapCompareFunc compare_func); 00106 00113 void binary_heap_free(BinaryHeap *heap); 00114 00125 int binary_heap_insert(BinaryHeap *heap, BinaryHeapValue value); 00126 00135 BinaryHeapValue binary_heap_pop(BinaryHeap *heap); 00136 00144 int binary_heap_num_entries(BinaryHeap *heap); 00145 00146 #ifdef __cplusplus 00147 } 00148 #endif 00149 00150 #endif /* #ifndef ALGORITHM_BINARY_HEAP_H */ 00151