rizin/librz/util/ht/ht_up.c
Anton Angelov 95f94ae258
refactor: SwissTable implementation for ht (#5860)
* Add ht benchmarks
* Initial implementation
* Finalize native per-group lookup support
* Lookup SSE2 implementation
* Improve hashing
* Add support for custom elem_size
* Avoid double h2 hashing when reserving slot
* Make custom elem_size support conditional
* Fix issues with bitwise and default lookup implementations
* Implement deletion trick optimization
* Track growth_size instead of deleted_slots
* Refactor SDB to access ht via API instead of internals
* Modify SDB tests which rely on hashtable order
* Fix SDB build warnings
* Fix bug with finding next power of two
* foreach_kv to return a bool result
* Change SDB diff order expected by serialize_analysis unit test
* Fix bug in the bitwise lookup implementation
* Remove second call to rz_core_init() which causes memory leaks
* Update some regression tests to accept reordered output
* Adapt ht clear to new implementation
* Use fini_kv_pair and fix 1 potential leak on malloc failure
* Fix cmd/types test after merge
* Avoid second call to calsize_key and avoid iter leaks on malloc failure
* Improve hash distribution
* Extend benchmark suite
* Fix bug with string hashing
* Branchless write to mirrored ctrl bytes
* Simplify string hash and remove potential UB
* Move RZ_PREFETCH macro to rz_types.h
* Add SSE2 discovery in Meson
* Forward SDB string hash function to ht string hash
* Try to revert test_cpu_profiles() to avoid relying on a baked SDB file
* Revert SDB/CDB hash function change
* Fix SDB reference to HT hash function instead of CDB hash
* Change calloc to malloc
* Avoid storing/checking key_len and key_value if they are ut64
* Improve string hash function
* Rename default hash functions
* Improve bench code
* linter.yml: set clang-path to point to llvm-18
2026-03-02 12:31:35 +08:00

54 lines
1.8 KiB
C

// SPDX-FileCopyrightText: 2016-2018 crowell
// SPDX-FileCopyrightText: 2016-2018 pancake <pancake@nopcode.org>
// SPDX-FileCopyrightText: 2016-2018 ret2libc <sirmy15@gmail.com>
// SPDX-FileCopyrightText: 2024 pelijah
// SPDX-License-Identifier: BSD-3-Clause
#include <rz_util/ht_up.h>
#include "ht_inc.c"
static void fini_kv_val(HT_(Kv) *kv, void *user) {
HT_(FreeValue) func = (HT_(FreeValue))user;
if (func) {
func(kv->value);
}
}
static void init_options(HT_(Options) *opt, HT_(DupValue) valdup, HT_(FreeValue) valfree) {
opt->cmp = NULL;
opt->hashfn = NULL;
opt->dupkey = NULL;
opt->dupvalue = valdup;
opt->calcsizeK = NULL;
opt->calcsizeV = NULL;
opt->finiKV = fini_kv_val;
opt->finiKV_user = (void *)valfree;
opt->elem_size = 0;
}
/**
* \brief Create a new hash table that has ut64 as key and void* as value.
* \param valdup Function to making copy of a value when inserting
* If NULL simple assignment operator is used for copy.
* \param valfree Function to releasing a stored value
* If NULL data is not freed.
*/
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(RZ_NULLABLE HT_(DupValue) valdup, RZ_NULLABLE HT_(FreeValue) valfree) {
HT_(Options) opt;
init_options(&opt, valdup, valfree);
return internal_ht_new(0, &opt);
}
/**
* \brief Create a new hash table that has ut64 as key and void* as value
* with preallocated buckets for \p initial_size entries.
* \param initial_size Initial size of the hash table
* \param valdup Function to making copy of a value when inserting
* If NULL simple assignment operator is used for copy.
* \param valfree Function to releasing a stored value
*/
RZ_API RZ_OWN HtName_(Ht) *Ht_(new_size)(ut32 initial_size, RZ_NULLABLE HT_(DupValue) valdup, RZ_NULLABLE HT_(FreeValue) valfree) {
HT_(Options) opt;
init_options(&opt, valdup, valfree);
return Ht_(new_opt_size)(&opt, initial_size);
}