lsquic_hash.h revision a74702c6
1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_hash.c -- A generic hash 4 */ 5 6#ifndef LSQUIC_HASH_H 7#define LSQUIC_HASH_H 8 9struct lsquic_hash; 10 11struct lsquic_hash_elem 12{ 13 TAILQ_ENTRY(lsquic_hash_elem) 14 qhe_next_bucket, 15 qhe_next_all; 16 const void *qhe_key_data; 17 void *qhe_value; 18 unsigned qhe_key_len; 19 unsigned qhe_hash_val; 20 enum { 21 QHE_HASHED = 1 << 0, 22 } qhe_flags; 23}; 24 25struct lsquic_hash * 26lsquic_hash_create (void); 27 28struct lsquic_hash * 29lsquic_hash_create_ext (int (*cmp)(const void *, const void *, size_t), 30 unsigned (*hash)(const void *, size_t, unsigned seed)); 31 32void 33lsquic_hash_destroy (struct lsquic_hash *); 34 35struct lsquic_hash_elem * 36lsquic_hash_insert (struct lsquic_hash *, const void *key, unsigned key_sz, 37 void *value, struct lsquic_hash_elem *); 38 39struct lsquic_hash_elem * 40lsquic_hash_find (struct lsquic_hash *, const void *key, unsigned key_sz); 41 42#define lsquic_hashelem_getdata(el) ((el)->qhe_value) 43 44void 45lsquic_hash_erase (struct lsquic_hash *, struct lsquic_hash_elem *); 46 47void 48lsquic_hash_reset_iter (struct lsquic_hash *); 49 50struct lsquic_hash_elem * 51lsquic_hash_first (struct lsquic_hash *); 52 53struct lsquic_hash_elem * 54lsquic_hash_next (struct lsquic_hash *); 55 56unsigned 57lsquic_hash_count (struct lsquic_hash *); 58 59size_t 60lsquic_hash_mem_used (const struct lsquic_hash *); 61#endif 62