#ifndef SEEN_HEAP_H #define SEEN_HEAP_H #include #include /* Efficient unordered vector */ struct heap_t { void** data; /* Array of pointers to data */ int count; /* Current number of items */ int capacity; /* Maximum number of items before growth */ int step; /* Number of pointers to allocate at a time */ size_t size; /* Size of an element of data */ void* (*alloc)(size_t); /* Function to allocate new items */ void (*dealloc)(void*); /* Function to deallocate items */ }; extern void* new_from_heap(struct heap_t* heap); extern int delete_from_heap(struct heap_t* heap, void* data); extern void process_heap(struct heap_t* heap, void (*proc)(void*)); extern void process_heap_va(struct heap_t* heap, void (*proc)(void*, va_list), ...); extern void empty_heap(struct heap_t* heap); extern struct heap_t* _create_heap(size_t size, int capacity, int step, void*(*alloc)(size_t), void(*dealloc)(void*)); extern void destroy_heap(struct heap_t* heap); #define create_heap(type, cap, step, alloc, dealloc)\ (_create_heap(sizeof(type), (cap), (step), (alloc), (dealloc))) #define create_basic_heap(type)\ (_create_heap(sizeof(type), 0, 1, malloc, free)) #define create_fixed_heap(type, size)\ (_create_heap(sizeof(type), (size), 0, malloc, free)) #endif