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