Allocation of resources for the heap. */
| 39 | |
| 40 | /* Allocation of resources for the heap. */ |
| 41 | struct priorityqueue *priorityqueue_new(const tal_t *ctx, |
| 42 | size_t max_num_nodes) { |
| 43 | struct priorityqueue *q = tal(ctx, struct priorityqueue); |
| 44 | /* check allocation */ |
| 45 | if (!q) return NULL; |
| 46 | |
| 47 | q->value = tal_arr(q, s64, max_num_nodes); |
| 48 | q->base = tal_arr(q, u32, max_num_nodes); |
| 49 | q->heapptr = tal_arrz(q, u32 *, max_num_nodes); |
| 50 | |
| 51 | /* check allocation */ |
| 52 | if (!q->value || !q->base || !q->heapptr) return tal_free(q); |
| 53 | |
| 54 | q->heapsize = 0; |
| 55 | q->gheap_ctx.fanout = 2; |
| 56 | q->gheap_ctx.page_chunks = 1024; |
| 57 | q->gheap_ctx.item_size = sizeof(q->base[0]); |
| 58 | q->gheap_ctx.less_comparer = priorityqueue_less_comparer; |
| 59 | q->gheap_ctx.less_comparer_ctx = NULL; |
| 60 | q->gheap_ctx.item_mover = priorityqueue_item_mover; |
| 61 | return q; |
| 62 | } |
| 63 | |
| 64 | void priorityqueue_init(struct priorityqueue *q) { |
| 65 | const size_t max_num_nodes = tal_count(q->value); |