zhangmeng
2024-04-22 16935f4aebffdd1b6580b844391a0aa0f4f3012b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
 
#ifndef ZT_HASH_H
#define ZT_HASH_H
 
#include <stdint.h>
 
// This code is derived from id hash, but supports 64-bit IDs.
 
typedef struct zt_hash       zt_hash;
typedef struct zt_hash_entry zt_hash_entry;
 
// NB: These details are entirely private to the hash implementation.
// They are provided here to facilitate inlining in structures.
struct zt_hash {
    size_t         ih_cap;
    size_t         ih_count;
    size_t         ih_load;
    size_t         ih_minload; // considers placeholders
    size_t         ih_maxload;
    uint64_t       ih_minval;
    uint64_t       ih_maxval;
    uint64_t       ih_dynval;
    zt_hash_entry *ih_entries;
};
 
extern int  zt_hash_init(zt_hash **);
extern void zt_hash_fini(zt_hash *);
extern void zt_hash_limits(zt_hash *, uint64_t, uint64_t, uint64_t);
extern int  zt_hash_find(zt_hash *, uint64_t, void **);
extern int  zt_hash_remove(zt_hash *, uint64_t);
extern int  zt_hash_insert(zt_hash *, uint64_t, void *);
extern int  zt_hash_alloc(zt_hash *, uint64_t *, void *);
 
#endif // CORE_IDHASH_H