diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-06-27 22:42:17 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-06-27 22:42:17 +0000 |
commit | a74cd2a1bd92eac6a4140d0794ac4b557be6c133 (patch) | |
tree | fdb341d0c7fecdbafc8f42cdc612076ebb23e024 /src/idxset.c | |
parent | 010378643e89e2ca4ea3502cb7dc6d8e16480832 (diff) |
add name registrar
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@39 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/idxset.c')
-rw-r--r-- | src/idxset.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/idxset.c b/src/idxset.c index ea609f60..090bfc72 100644 --- a/src/idxset.c +++ b/src/idxset.c @@ -15,29 +15,43 @@ struct idxset_entry { }; struct idxset { - unsigned (*hash_func) (void *p); - int (*compare_func)(void *a, void *b); + unsigned (*hash_func) (const void *p); + int (*compare_func)(const void *a, const void *b); unsigned hash_table_size, n_entries; struct idxset_entry **hash_table, **array, *iterate_list_head, *iterate_list_tail; uint32_t index, start_index, array_size; }; -static unsigned trivial_hash_func(void *p) { +unsigned idxset_string_hash_func(const void *p) { + unsigned hash = 0; + const char *c; + + for (c = p; *c; c++) + hash = 31 * hash + *c; + + return hash; +} + +int idxset_string_compare_func(const void *a, const void *b) { + return strcmp(a, b); +} + +unsigned idxset_trivial_hash_func(const void *p) { return (unsigned) p; } -static int trivial_compare_func(void *a, void *b) { +int idxset_trivial_compare_func(const void *a, const void *b) { return a != b; } -struct idxset* idxset_new(unsigned (*hash_func) (void *p), int (*compare_func) (void*a, void*b)) { +struct idxset* idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) { struct idxset *s; s = malloc(sizeof(struct idxset)); assert(s); - s->hash_func = hash_func ? hash_func : trivial_hash_func; - s->compare_func = compare_func ? compare_func : trivial_compare_func; + s->hash_func = hash_func ? hash_func : idxset_trivial_hash_func; + s->compare_func = compare_func ? compare_func : idxset_trivial_compare_func; s->hash_table_size = 1023; s->hash_table = malloc(sizeof(struct idxset_entry*)*s->hash_table_size); assert(s->hash_table); |