| 41 | /* Allocate memory for the heap. */ |
| 42 | |
| 43 | struct heap * |
| 44 | heap_alloc (int (*compare) (void const *, void const *), idx_t n_reserve) |
| 45 | { |
| 46 | struct heap *heap = xmalloc (sizeof *heap); |
| 47 | |
| 48 | if (n_reserve == 0) |
| 49 | n_reserve = 1; |
| 50 | |
| 51 | heap->array = xnmalloc (n_reserve, sizeof *(heap->array)); |
| 52 | |
| 53 | heap->array[0] = NULL; |
| 54 | heap->capacity = n_reserve; |
| 55 | heap->count = 0; |
| 56 | heap->compare = compare ? compare : heap_default_compare; |
| 57 | |
| 58 | return heap; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | static int |