26 #ifndef CDCONTAINERS_INCLUDE_CDCONTAINERS_HEAP_H 27 #define CDCONTAINERS_INCLUDE_CDCONTAINERS_HEAP_H 230 #ifdef CDC_USE_SHORT_NAMES 234 #define heap_ctor(...) cdc_heap_ctor(__VA_ARGS__) 235 #define heap_ctorl(...) cdc_heap_ctorl(__VA_ARGS__) 236 #define heap_ctorv(...) cdc_heap_ctorv(__VA_ARGS__) 237 #define heap_dtor(...) cdc_heap_dtor(__VA_ARGS__) 240 #define heap_top(...) cdc_heap_top(__VA_ARGS__) 243 #define heap_empty(...) cdc_heap_empty(__VA_ARGS__) 244 #define heap_size(...) cdc_heap_size(__VA_ARGS__) 247 #define heap_extract_top(...) cdc_heap_extract_top(__VA_ARGS__) 248 #define heap_riinsert(...) cdc_heap_riinsert(__VA_ARGS__) 249 #define heap_insert(...) cdc_heap_insert(__VA_ARGS__) 250 #define heap_change_key(...) cdc_heap_change_key(__VA_ARGS__) 251 #define heap_clear(...) cdc_heap_clear(__VA_ARGS__) 252 #define heap_swap(...) cdc_heap_swap(__VA_ARGS__) 255 #define heap_merge(...) cdc_heap_merge(__VA_ARGS__) 257 #define heap_is_heap(...) cdc_heap_is_heap(__VA_ARGS__) 260 #define heap_iter_data(...) cdc_heap_iter_data(__VA_ARGS__) 261 #define heap_iter_is_eq(...) cdc_heap_iter_is_eq(__VA_ARGS__) 264 #endif // CDCONTAINERS_INCLUDE_CDCONTAINERS_HEAP_H enum cdc_stat cdc_heap_merge(struct cdc_heap *h, struct cdc_heap *other)
Merges two heaps. In the heap h will be the result of the merger, and the heap other will remain empt...
void cdc_heap_change_key(struct cdc_heap *h, struct cdc_heap_iter *pos, void *key)
Changes the item key on the pos position in the heap.
static enum cdc_stat cdc_heap_insert(struct cdc_heap *h, void *key)
Inserts element key to the heap.
Definition: heap.h:159
enum cdc_stat cdc_heap_ctorl(struct cdc_heap **h, struct cdc_data_info *info,...)
Constructs a heap, initialized by an arbitrary number of pointers. The last item must be NULL...
struct cdc_array * container
Definition: heap.h:52
enum cdc_stat cdc_heap_ctorv(struct cdc_heap **h, struct cdc_data_info *info, va_list args)
Constructs a heap, initialized by args. The last item must be NULL.
void cdc_heap_swap(struct cdc_heap *a, struct cdc_heap *b)
Swaps heaps a and b. This operation is very fast and never fails.
static bool cdc_heap_iter_is_eq(struct cdc_heap_iter *it1, struct cdc_heap_iter *it2)
Returns false if the iterator it1 equal to the iterator it2, otherwise returns false.
Definition: heap.h:220
void cdc_heap_clear(struct cdc_heap *h)
Removes all the elements from the heap.
The cdc_array is a struct and functions that provide a dynamic array.
enum cdc_stat cdc_heap_ctor(struct cdc_heap **h, struct cdc_data_info *info)
Constructs an empty heap.
The cdc_array is service struct.
Definition: array.h:50
The cdc_heap_iter struct.
Definition: heap.h:51
The cdc_heap struct.
Definition: heap.h:42
void cdc_heap_extract_top(struct cdc_heap *h)
Extracts the top item from the heap. This function assumes that the heap isn't empty.
static void * cdc_array_front(struct cdc_array *v)
Returns a first element in the array.
Definition: array.h:142
struct cdc_array * array
Definition: heap.h:43
cdc_stat
Definition: status.h:24
static size_t cdc_heap_size(struct cdc_heap *h)
Returns the number of items in the heap.
Definition: heap.h:112
enum cdc_stat cdc_heap_riinsert(struct cdc_heap *h, void *key, struct cdc_heap_iter *ret)
Inserts element key to the heap. Write an iterator pointing to a new element in the ret...
bool cdc_heap_is_heap(struct cdc_heap *h)
Checks the heap property.
The cdc_data_info struct used to initialize contaners.
Definition: common.h:71
static size_t cdc_array_size(struct cdc_array *v)
Returns the number of elements in the array.
Definition: array.h:209
static void * cdc_heap_iter_data(struct cdc_heap_iter *it)
Returns a pointer to the key of current item.
Definition: heap.h:209
size_t current
Definition: heap.h:53
static bool cdc_array_empty(struct cdc_array *v)
Checks if the array has no elements.
Definition: array.h:197
static bool cdc_heap_empty(struct cdc_heap *h)
Returns true if the heap has size 0; otherwise returns false.
Definition: heap.h:124
static void * cdc_array_get(struct cdc_array *v, size_t index)
Returns an element at index position in the array.
Definition: array.h:118
static void * cdc_heap_top(struct cdc_heap *h)
Returns a pointer to the heap's top item. This function assumes that the heap isn't empty...
Definition: heap.h:99
void cdc_heap_dtor(struct cdc_heap *h)
Destroys the heap.