-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheap.h
More file actions
42 lines (31 loc) · 1.15 KB
/
heap.h
File metadata and controls
42 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdbool.h>
/*
* Interface for heap.c
* heap.c implements a priority queue by way of a max heap
* Implementation includes a function to increase the key of a particular item
* HeapInsert, HeapIncreaseKey and HeapExtract are log(n) operations
* Heap is automatically resized when too big or too small
* Control resizing behavior through RESIZE_FACTOR in heap.c
*/
#ifndef _heap_h
#define _heap_h
struct HeapNode {
void *data; // pointer to data object
struct Heap *heap; // heap this HeapNode belongs to
float key; // node's priority
int offset; // node's position in heap (its offset)
};
struct Heap;
struct Heap *HeapNew();
void HeapDestroy(struct Heap *heap);
struct HeapNode *HeapExtract(struct Heap *heap);
bool HeapIncreaseKey(struct HeapNode *node, float key);
// Use HeapNode reference returned by HeapInsert()
struct HeapNode *HeapInsert(struct Heap *heap, void *data, float key);
/*
* When a node is inserted, function returns a HeapNode object
* HeapNode is used as a reference for HeapIncreaseKey
* Discard return value if this functionality isn't needed
*/
bool HeapIsEmpty(struct Heap *heap);
#endif