lsquic_hash.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 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
28void
29lsquic_hash_destroy (struct lsquic_hash *);
30
31struct lsquic_hash_elem *
32lsquic_hash_insert (struct lsquic_hash *, const void *key, unsigned key_sz,
33                                    void *value, struct lsquic_hash_elem *);
34
35struct lsquic_hash_elem *
36lsquic_hash_find (struct lsquic_hash *, const void *key, unsigned key_sz);
37
38#define lsquic_hashelem_getdata(el) ((el)->qhe_value)
39
40void
41lsquic_hash_erase (struct lsquic_hash *, struct lsquic_hash_elem *);
42
43void
44lsquic_hash_reset_iter (struct lsquic_hash *);
45
46struct lsquic_hash_elem *
47lsquic_hash_first (struct lsquic_hash *);
48
49struct lsquic_hash_elem *
50lsquic_hash_next (struct lsquic_hash *);
51
52unsigned
53lsquic_hash_count (struct lsquic_hash *);
54
55size_t
56lsquic_hash_mem_used (const struct lsquic_hash *);
57#endif
58