lsquic_min_heap.h revision fbc6cc04
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_min_heap.h -- Min-heap for pointers
4 */
5
6#ifndef LSQUIC_MIN_HEAP_H
7#define LSQUIC_MIN_HEAP_H 1
8
9
10struct min_heap_elem
11{
12    void                *mhe_item;
13    uint64_t             mhe_val;
14};
15
16
17struct min_heap
18{
19    struct min_heap_elem    *mh_elems;
20    unsigned                 mh_nalloc,
21                             mh_nelem;
22};
23
24
25void
26lsquic_mh_insert (struct min_heap *, void *item, uint64_t val);
27
28void *
29lsquic_mh_pop (struct min_heap *);
30
31#define lsquic_mh_peek(heap) ((heap)->mh_elems[0].mhe_item)
32
33#define lsquic_mh_count(heap) (+(heap)->mh_nelem)
34
35#define lsquic_mh_nalloc(heap) (+(heap)->mh_nalloc)
36
37#define MHE_PARENT(i) ((i - 1) / 2)
38#define MHE_LCHILD(i) (2 * i + 1)
39#define MHE_RCHILD(i) (2 * i + 2)
40
41#endif
42