X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fhashmap.c;h=6928118615ba48306f15b9afee225550a62ed758;hp=0d89da461406b30b022b0760289acd20e457b217;hb=64661ee70d5a10c6208a1cb66ecd8b158e2d8bc5;hpb=39c2a6f19301c0042142149fdaa34a5f8cf71c0e diff --git a/src/hashmap.c b/src/hashmap.c index 0d89da461..692811861 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -55,10 +55,10 @@ struct pool { unsigned n_used; }; -struct pool *first_hashmap_pool = NULL; +static struct pool *first_hashmap_pool = NULL; static void *first_hashmap_tile = NULL; -struct pool *first_entry_pool = NULL; +static struct pool *first_entry_pool = NULL; static void *first_entry_tile = NULL; static void* allocate_tile(struct pool **first_pool, void **first_tile, size_t tile_size) { @@ -124,11 +124,13 @@ __attribute__((destructor)) static void cleanup_pool(void) { #endif unsigned string_hash_func(const void *p) { - unsigned hash = 0; - const char *c; + unsigned hash = 5381; + const signed char *c; + + /* DJB's hash function */ for (c = p; *c; c++) - hash = 31 * hash + (unsigned) *c; + hash = (hash << 5) + hash + (unsigned) *c; return hash; } @@ -556,6 +558,17 @@ void* hashmap_first(Hashmap *h) { return h->iterate_list_head->value; } +void* hashmap_first_key(Hashmap *h) { + + if (!h) + return NULL; + + if (!h->iterate_list_head) + return NULL; + + return (void*) h->iterate_list_head->key; +} + void* hashmap_last(Hashmap *h) { if (!h)