1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov/* 350aadb33SDmitri Tikhonov * lsquic_hash.c -- A generic hash 450aadb33SDmitri Tikhonov */ 550aadb33SDmitri Tikhonov 650aadb33SDmitri Tikhonov#ifndef LSQUIC_HASH_H 750aadb33SDmitri Tikhonov#define LSQUIC_HASH_H 850aadb33SDmitri Tikhonov 950aadb33SDmitri Tikhonovstruct lsquic_hash; 105392f7a3SLiteSpeed Tech 115392f7a3SLiteSpeed Techstruct lsquic_hash_elem 125392f7a3SLiteSpeed Tech{ 135392f7a3SLiteSpeed Tech TAILQ_ENTRY(lsquic_hash_elem) 145392f7a3SLiteSpeed Tech qhe_next_bucket, 155392f7a3SLiteSpeed Tech qhe_next_all; 165392f7a3SLiteSpeed Tech const void *qhe_key_data; 175392f7a3SLiteSpeed Tech void *qhe_value; 185392f7a3SLiteSpeed Tech unsigned qhe_key_len; 195392f7a3SLiteSpeed Tech unsigned qhe_hash_val; 205392f7a3SLiteSpeed Tech enum { 215392f7a3SLiteSpeed Tech QHE_HASHED = 1 << 0, 225392f7a3SLiteSpeed Tech } qhe_flags; 235392f7a3SLiteSpeed Tech}; 2450aadb33SDmitri Tikhonov 2550aadb33SDmitri Tikhonovstruct lsquic_hash * 2650aadb33SDmitri Tikhonovlsquic_hash_create (void); 2750aadb33SDmitri Tikhonov 2892f6e17bSDmitri Tikhonovstruct lsquic_hash * 2992f6e17bSDmitri Tikhonovlsquic_hash_create_ext (int (*cmp)(const void *, const void *, size_t), 3092f6e17bSDmitri Tikhonov unsigned (*hash)(const void *, size_t, unsigned seed)); 3192f6e17bSDmitri Tikhonov 3250aadb33SDmitri Tikhonovvoid 3350aadb33SDmitri Tikhonovlsquic_hash_destroy (struct lsquic_hash *); 3450aadb33SDmitri Tikhonov 3550aadb33SDmitri Tikhonovstruct lsquic_hash_elem * 3650aadb33SDmitri Tikhonovlsquic_hash_insert (struct lsquic_hash *, const void *key, unsigned key_sz, 375392f7a3SLiteSpeed Tech void *value, struct lsquic_hash_elem *); 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonovstruct lsquic_hash_elem * 4050aadb33SDmitri Tikhonovlsquic_hash_find (struct lsquic_hash *, const void *key, unsigned key_sz); 4150aadb33SDmitri Tikhonov 425392f7a3SLiteSpeed Tech#define lsquic_hashelem_getdata(el) ((el)->qhe_value) 4350aadb33SDmitri Tikhonov 4450aadb33SDmitri Tikhonovvoid 4550aadb33SDmitri Tikhonovlsquic_hash_erase (struct lsquic_hash *, struct lsquic_hash_elem *); 4650aadb33SDmitri Tikhonov 4750aadb33SDmitri Tikhonovvoid 4850aadb33SDmitri Tikhonovlsquic_hash_reset_iter (struct lsquic_hash *); 4950aadb33SDmitri Tikhonov 5050aadb33SDmitri Tikhonovstruct lsquic_hash_elem * 5150aadb33SDmitri Tikhonovlsquic_hash_first (struct lsquic_hash *); 5250aadb33SDmitri Tikhonov 5350aadb33SDmitri Tikhonovstruct lsquic_hash_elem * 5450aadb33SDmitri Tikhonovlsquic_hash_next (struct lsquic_hash *); 5550aadb33SDmitri Tikhonov 5650aadb33SDmitri Tikhonovunsigned 5750aadb33SDmitri Tikhonovlsquic_hash_count (struct lsquic_hash *); 5850aadb33SDmitri Tikhonov 59c51ce338SDmitri Tikhonovsize_t 60c51ce338SDmitri Tikhonovlsquic_hash_mem_used (const struct lsquic_hash *); 6150aadb33SDmitri Tikhonov#endif 62