rizin/librz/util/ht/ht_sp.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

46 lines
1.3 KiB
C

// SPDX-FileCopyrightText: 2024 pelijah
// SPDX-License-Identifier: BSD-3-Clause
#include "sdb.h"
#include <rz_util/ht_sp.h>
#include "ht_inc.c"
static void fini_kv(HT_(Kv) *kv, void *user) {
HT_(FreeValue) func = (HT_(FreeValue))user;
free(kv->key);
if (func) {
func(kv->value);
}
}
static void fini_kv_val(HT_(Kv) *kv, void *user) {
HT_(FreeValue) func = (HT_(FreeValue))user;
if (func) {
func(kv->value);
}
}
/**
* \brief Create a new hash table that has C-string as key and void* as value.
* \param key_opt Defines how key is stored
* \param dup_val Function to making copy of a value when inserting
* \param free_val Function to releasing a stored value
*
* Keys are compared using strcmp function.
* Size of keys is calculated using strlen function.
* Copies of keys are made using rz_str_dup function if appropriate option is set.
*/
RZ_API RZ_OWN HtName_(Ht) *Ht_(new)(HtStrOption key_opt, RZ_NULLABLE HT_(DupValue) dup_val, RZ_NULLABLE HT_(FreeValue) free_val) {
HT_(Options) opt = {
.cmp = (HT_(Comparator))strcmp,
.hashfn = NULL,
.dupkey = key_opt == HT_STR_DUP ? (HT_(DupKey))rz_str_dup : NULL,
.dupvalue = dup_val,
.calcsizeK = (HT_(CalcSizeK))strlen,
.calcsizeV = NULL,
.finiKV = key_opt == HT_STR_CONST ? fini_kv_val : fini_kv,
.finiKV_user = (void *)free_val,
.elem_size = 0,
};
return internal_ht_new(0, &opt);
}