00001 #ifdef __cplusplus
00002 extern "C" {
00003 #endif
00004
00005 #ifndef CDSA_HEAP_H
00006 #define CDSA_HEAP_H
00007
00008 #include <stdlib.h>
00009 #include <stdbool.h>
00010
00011 #include "utils.h"
00012
00024 typedef enum HeapType
00025 {
00026 MAX_HEAP, MIN_HEAP
00027 } HeapType;
00028
00034 #define DEFAULT_HEAP_CAPACITY 16
00035
00036
00058 typedef struct Heap Heap;
00059 struct Heap;
00060
00061
00088 cdsa_status_t heap_new(Heap **new_heap, size_t capacity, HeapType heap_type,
00089 cdsa_compare_func_t compare, cdsa_destroy_func1_t destroy);
00090
00126 cdsa_status_t heap_new_from_ptr_array(Heap **new_heap, size_t capacity, HeapType heap_type,
00127 void *arr, size_t nmemb, size_t ptrsize,
00128 cdsa_compare_func_t compare,
00129 cdsa_destroy_func1_t destroy);
00130
00165 cdsa_status_t
00166 heap_new_from_data_array(Heap **new_heap, size_t capacity, HeapType heap_type,
00167 void *arr, size_t nmemb, size_t membsize,
00168 cdsa_compare_func_t compare,
00169 cdsa_destroy_func1_t destroy);
00170
00181 cdsa_status_t heap_destroy(Heap **heap);
00182
00192 cdsa_status_t heap_type(Heap *heap, HeapType *heap_type);
00193
00203 cdsa_status_t heap_is_empty(Heap *heap, bool *is_empty);
00204
00216 cdsa_status_t heap_size(Heap *heap, size_t *size);
00217
00232 cdsa_status_t heap_capacity(Heap *heap, size_t *capacity);
00233
00242 cdsa_status_t heap_push(Heap *heap, void *data);
00243
00253 cdsa_status_t heap_pop(Heap *heap, void *ptr);
00254
00264 cdsa_status_t heap_peek(Heap *heap, void *ptr);
00265
00272 cdsa_status_t heap_clear(Heap *heap);
00273
00293 cdsa_status_t heap_sort(void *arr, size_t nmemb, size_t ptrsize,
00294 cdsa_compare_func_t compare);
00295
00296
00297 #ifdef __cplusplus
00298 }
00299 #endif
00300
00301 #endif
00302