Debian Codegraph @

crt/aws-c-common/include/aws/common/private/hash_table_impl.h

raw symbols SCIP
1 #ifndef AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H
2 #define AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/common/common.h>
10 #include <aws/common/hash_table.h>
11 #include <aws/common/math.h>
12
13 struct hash_table_entry {
14 struct aws_hash_element element;
15 uint64_t hash_code; /* hash code (0 signals empty) */
16 };
17
18 /* Using a flexible array member is the C99 compliant way to have the hash_table_entries
19 * immediately follow the struct.
20 *
21 * MSVC doesn't know this for some reason so we need to use a pragma to make
22 * it happy.
23 */
24 #ifdef _MSC_VER
25 # pragma warning(push)
26 # pragma warning(disable : 4200)
27 #endif
28 struct hash_table_state {
29 aws_hash_fn *hash_fn;
30 aws_hash_callback_eq_fn *equals_fn;
31 aws_hash_callback_destroy_fn *destroy_key_fn;
32 aws_hash_callback_destroy_fn *destroy_value_fn;
33 struct aws_allocator *alloc;
34
35 size_t size, entry_count;
36 size_t max_load;
37 /* We AND a hash value with mask to get the slot index */
38 size_t mask;
39 double max_load_factor;
40 /* actually variable length */
41 struct hash_table_entry slots[];
42 };
43 #ifdef _MSC_VER
44 # pragma warning(pop)
45 #endif
46
47 /**
48 * Best-effort check of hash_table_state data-structure invariants
49 * Some invariants, such as that the number of entries is actually the
50 * same as the entry_count field, would require a loop to check
51 */
52 bool hash_table_state_is_valid(const struct hash_table_state *map);
53
54 /**
55 * Determine the total number of bytes needed for a hash-table with
56 * "size" slots. If the result would overflow a size_t, return
57 * AWS_OP_ERR; otherwise, return AWS_OP_SUCCESS with the result in
58 * "required_bytes".
59 */
60 int hash_table_state_required_bytes(size_t size, size_t *required_bytes);
61
62 #endif /* AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H */