1 // SPDX-License-Identifier: GPL-2.0
3 * Implementation of the symbol table type.
8 #include <linux/kernel.h>
9 #include <linux/string.h>
10 #include <linux/errno.h>
13 static unsigned int symhash(const void *key)
17 * Public domain from cdb v0.75
19 unsigned int hash = 5381;
22 while ((c = *(const unsigned char *)key++))
23 hash = ((hash << 5) + hash) ^ c;
28 static int symcmp(const void *key1, const void *key2)
30 const char *keyp1, *keyp2;
34 return strcmp(keyp1, keyp2);
37 static const struct hashtab_key_params symtab_key_params = {
42 int symtab_init(struct symtab *s, u32 size)
45 return hashtab_init(&s->table, size);
48 int symtab_insert(struct symtab *s, char *name, void *datum)
50 return hashtab_insert(&s->table, name, datum, symtab_key_params);
53 void *symtab_search(struct symtab *s, const char *name)
55 return hashtab_search(&s->table, name, symtab_key_params);