/*
- * Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
+ * Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
#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_pair {
void *key;
void *value;
- unsigned int hash;
+ size_t hash;
struct hashtable_list list;
};
};
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;
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
*/
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