1
0
Fork 0

More implementation code for heaps.

This commit is contained in:
wael 2022-01-02 17:09:36 +02:00
parent 48dcdeeeb9
commit 7af8990e67
No known key found for this signature in database
GPG Key ID: C0A5FBF4558963D4
2 changed files with 13 additions and 3 deletions

View File

@ -84,6 +84,12 @@ static inline void* extract_max_max_heap(max_heap_t *heap) {
return data;
}
/* This function replaces the data in the heap's root. */
/* Might exhibit endefined behavior if heap is NULL or has no root. */
static inline void replace_root_max_heap(max_heap_t *heap, void *data) {
heap->root->data = data;
}
/* This function returns the size of the heap, will return -1 on error! */
static inline size_t size_max_heap(max_heap_t *heap) {
return (heap == NULL) ? MAX_HEAP_CHECK_ERROR : heap->size;

View File

@ -77,9 +77,9 @@ static inline max_heap_t* insert_node_data_max_heap(max_heap_t *heap, void *data
/* This function extracts the max. */
static inline void* extract_max_max_heap(max_heap_t *heap);
/* This function deletes the max. */
void delete_max_max_heap(max_heap_t *heap);
static inline void delete_max_max_heap(max_heap_t *heap);
/* This function replaces the root. */
void* replace_root_max_heap(max_heap_t *heap, void *data);
static inline void replace_root_max_heap(max_heap_t *heap, void *data);
/* This function returns the size of the heap. */
static inline size_t size_max_heap(max_heap_t *heap);
/* This function returns whether or not the heap is empty. */
@ -89,7 +89,9 @@ static inline void free_max_heap(max_heap_t *heap);
/* This function frees a whole heap, including data. */
static inline void free_max_heap_data(max_heap_t *heap, void (*free_function)(const void*));
/* This function inserts data to the heap. */
int insert_node_into_max_heap(max_heap_t *heap, max_heap_t *to_insert, int (*comparison_function)(const void*, const void*));
static inline int insert_node_into_max_heap(max_heap_t *heap, heap_node_t *to_insert, int (*comparison_function)(const void*, const void*));
/* This function inserts data to the heap. */
static inline int insert_data_into_max_heap(max_heap_t *heap, void *data, int (*comparison_function)(const void*, const void*));
/* This function searches for data in the heap. */
max_heap_t* search_in_max_heap(max_heap_t *heap, void *data, int (*comparison_function)(const void*, const void*));
/* This function finds the heap's depth (at the deepest leaf). */
@ -115,4 +117,6 @@ static inline void recursive_free_heap_node(heap_node_t *root);
static inline void recursive_free_heap_node_data(heap_node_t *root, void (*free_function)(const void*));
/* This function recursively looks for the max depth in the heap. */
static inline size_t calculate_max_heap_depth(heap_node_t *heap, size_t max);
/* This function handles insertion of a single node into a heap - relies on heapification upwards. */
static inline void insert_node_int_max_heap_recursive(heap_node_t *root, heap_node_t *node, int (*comparison_function)(const void*, const void*));
#endif /* MAX_HEAP_H */