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