mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-30 05:09:06 +08:00
libbpf: Extract generic string hashing function for reuse
Calculating a hash of zero-terminated string is a common need when using hashmap, so extract it for reuse. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20200926011357.2366158-5-andriin@fb.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
063eed6105
commit
897a0e79bd
@@ -90,14 +90,7 @@ struct btf_dump {
|
||||
|
||||
static size_t str_hash_fn(const void *key, void *ctx)
|
||||
{
|
||||
const char *s = key;
|
||||
size_t h = 0;
|
||||
|
||||
while (*s) {
|
||||
h = h * 31 + *s;
|
||||
s++;
|
||||
}
|
||||
return h;
|
||||
return str_hash(key);
|
||||
}
|
||||
|
||||
static bool str_equal_fn(const void *a, const void *b, void *ctx)
|
||||
|
||||
Reference in New Issue
Block a user