X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fhashtable.h;h=5aed14f2ef61855fe865828a773f0807be763d5e;hb=fa7c2ea070672d05b34b6341142a193e9a7d0a8c;hp=76666a413e15ef0d86062a12dcb4979a3fc6b585;hpb=61d0111323c7df3326d57856c7120c1af807a062;p=jansson.git diff --git a/src/hashtable.h b/src/hashtable.h index 76666a4..5aed14f 100644 --- a/src/hashtable.h +++ b/src/hashtable.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Petri Lehtinen + * Copyright (c) 2009-2011 Petri Lehtinen * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -8,19 +8,19 @@ #ifndef HASHTABLE_H #define HASHTABLE_H -typedef unsigned int (*key_hash_fn)(const void *key); +typedef size_t (*key_hash_fn)(const void *key); typedef int (*key_cmp_fn)(const void *key1, const void *key2); typedef void (*free_fn)(void *key); struct hashtable_list { - struct hashtable_list *prev; - struct hashtable_list *next; + struct hashtable_list *prev; + struct hashtable_list *next; }; struct hashtable_pair { void *key; void *value; - unsigned int hash; + size_t hash; struct hashtable_list list; }; @@ -30,9 +30,9 @@ struct hashtable_bucket { }; typedef struct hashtable { - unsigned int size; + size_t size; struct hashtable_bucket *buckets; - unsigned int num_buckets; /* index to primes[] */ + size_t num_buckets; /* index to primes[] */ struct hashtable_list list; key_hash_fn hash_key; @@ -135,6 +135,15 @@ void *hashtable_get(hashtable_t *hashtable, const void *key); int hashtable_del(hashtable_t *hashtable, const void *key); /** + * hashtable_clear - Clear hashtable + * + * @hashtable: The hashtable object + * + * Removes all items from the hashtable. + */ +void hashtable_clear(hashtable_t *hashtable); + +/** * hashtable_iter - Iterate over hashtable * * @hashtable: The hashtable object @@ -152,6 +161,17 @@ int hashtable_del(hashtable_t *hashtable, const void *key); void *hashtable_iter(hashtable_t *hashtable); /** + * hashtable_iter_at - Return an iterator at a specific key + * + * @hashtable: The hashtable object + * @key: The key that the iterator should point to + * + * Like hashtable_iter() but returns an iterator pointing to a + * specific key. + */ +void *hashtable_iter_at(hashtable_t *hashtable, const void *key); + +/** * hashtable_iter_next - Advance an iterator * * @hashtable: The hashtable object @@ -176,4 +196,12 @@ void *hashtable_iter_key(void *iter); */ void *hashtable_iter_value(void *iter); +/** + * hashtable_iter_set - Set the value pointed by an iterator + * + * @iter: The iterator + * @value: The value to set + */ +void hashtable_iter_set(hashtable_t *hashtable, void *iter, void *value); + #endif