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