From b2b0acbc5789823a33de9eabec10e2b8656f3632 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 24 Jan 2011 21:25:02 -0600 Subject: Initial implementation with new config system. --- module/hash.h | 110 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 43 deletions(-) (limited to 'module/hash.h') diff --git a/module/hash.h b/module/hash.h index a02b8e3..8649ed5 100644 --- a/module/hash.h +++ b/module/hash.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2004, Stefan Walter - * All rights reserved. + * Copyright (c) 2011, Collabora Ltd. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,6 +29,8 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. + * + * Author: Stef Waler */ /* @@ -56,15 +58,6 @@ #include -/* - * OPTIONAL FEATURES - * - * Features to define. You need to build both this file and - * the corresponding hash.c file with whatever options you set here. - * These affect the method signatures, so see the sections below - * for the actual options - */ - /* * ARGUMENT DOCUMENTATION * @@ -82,77 +75,108 @@ */ /* Abstract type for hash tables. */ -typedef struct hsh_t hsh_t; +typedef struct hash hash_t; -/* Abstract type for scanning hash tables. */ -typedef struct hsh_index_t hsh_index_t; +/* Type for scanning hash tables. */ +typedef struct hash_iter +{ + hash_t* ht; + struct hash_entry* ths; + struct hash_entry* next; + unsigned int index; +} hash_iter_t; + +typedef unsigned int (*hash_hash_func) (const void *data); + +typedef int (*hash_equal_func) (const void *one, + const void *two); + +typedef void (*hash_destroy_func) (void *data); /* ----------------------------------------------------------------------------- * MAIN */ /* - * hsh_create : Create a hash table + * hash_create : Create a hash table * - returns an allocated hashtable */ -hsh_t* hsh_create(void); +hash_t* hash_create (hash_hash_func hash_func, + hash_equal_func equal_func, + hash_destroy_func key_destroy_func, + hash_destroy_func value_destroy_func); /* - * hsh_free : Free a hash table + * hash_free : Free a hash table */ -void hsh_free(hsh_t* ht); +void hash_free (hash_t* ht); /* - * hsh_count: Number of values in hash table + * hash_count: Number of values in hash table * - returns the number of entries in hash table */ -unsigned int hsh_count(hsh_t* ht); +unsigned int hash_count (hash_t* ht); /* - * hsh_get: Retrieves a value from the hash table + * hash_get: Retrieves a value from the hash table * - returns the value of the entry */ -void* hsh_get(hsh_t* ht, const void* key, size_t klen); +void* hash_get (hash_t* ht, + const void *key); /* - * hsh_set: Set a value in the hash table + * hash_set: Set a value in the hash table * - returns 1 if the entry was added properly */ -int hsh_set(hsh_t* ht, const void* key, size_t klen, void* val); +int hash_set (hash_t* ht, + void *key, + void *value); /* - * hsh_rem: Remove a value from the hash table - * - returns the value of the removed entry + * hash_remove: Remove a value from the hash table + * - returns 1 if the entry was found */ -void* hsh_rem(hsh_t* ht, const void* key, size_t klen); +int hash_remove (hash_t* ht, + const void* key); /* - * hsh_first: Start enumerating through the hash table + * hash_first: Start enumerating through the hash table * - returns a hash iterator */ -hsh_index_t* hsh_first(hsh_t* ht); +void hash_iterate (hash_t* ht, + hash_iter_t *hi); /* - * hsh_next: Enumerate through hash table - * - returns the hash iterator or null when no more entries + * hash_next: Enumerate through hash table + * - sets key and value to key and/or value + * - returns whether there was another entry */ -hsh_index_t* hsh_next(hsh_index_t* hi); +int hash_next (hash_iter_t* hi, + void **key, + void **value); /* - * hsh_this: While enumerating get current value - * - returns the value that the iterator currently points to + * hash_clear: Clear all values from has htable. */ -void* hsh_this(hsh_index_t* hi, const void** key, size_t* klen); +void hash_clear (hash_t* ht); -/* - * hsh_clear: Clear all values from has htable. +/* ----------------------------------------------------------------------------- + * HASH FUNCTIONS */ -void hsh_clear(hsh_t* ht); -/* - * This can be passed as 'klen' in any of the above functions to indicate - * a string-valued key, and have hash compute the length automatically. - */ -#define HSH_KEY_STRING (-1) +unsigned int hash_string_hash (const void *string); + +int hash_string_equal (const void *string_one, + const void *string_two); + +unsigned int hash_ulongptr_hash (const void *to_ulong); + +int hash_ulongptr_equal (const void *ulong_one, + const void *ulong_two); + +unsigned int hash_direct_hash (const void *ptr); + +int hash_direct_equal (const void *ptr_one, + const void *ptr_two); -#endif /* __HSH_H__ */ +#endif /* __HASH_H__ */ -- cgit v1.2.3