From 7f609ec2aa5f3c4ec3635bf9ab3ac636089ec891 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 7 Jan 2004 06:13:43 +0000 Subject: - added BLI_ghash_size(), number of entries in table - added GHashIterator ADT, for iterating over GHash-tables --- source/blender/blenlib/BLI_ghash.h | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source/blender/blenlib/BLI_ghash.h') diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index 11dee5df57d..d2f2bcc95e4 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -37,6 +37,7 @@ struct GHash; typedef struct GHash GHash; +typedef struct GHashIterator GHashIterator; typedef unsigned int (*GHashHashFP) (void *key); typedef int (*GHashCmpFP) (void *a, void *b); @@ -50,6 +51,59 @@ void BLI_ghash_insert (GHash *gh, void *key, void *val); void* BLI_ghash_lookup (GHash *gh, void *key); int BLI_ghash_haskey (GHash *gh, void *key); +int BLI_ghash_size (GHash *gh); + +/* *** */ + + /** + * Create a new GHashIterator. The hash table must not be mutated + * while the iterator is in use, and the iterator will step exactly + * BLI_ghash_size(gh) times before becoming done. + * + * @param gh The GHash to iterate over. + * @return Pointer to a new DynStr. + */ +GHashIterator* BLI_ghashIterator_new (GHash *gh); + /** + * Free a GHashIterator. + * + * @param ghi The iterator to free. + */ +void BLI_ghashIterator_free (GHashIterator *ghi); + + /** + * Retrieve the key from an iterator. + * + * @param ghi The iterator. + * @return The key at the current index, or NULL if the + * iterator is done. + */ +void* BLI_ghashIterator_getKey (GHashIterator *ghi); + /** + * Retrieve the value from an iterator. + * + * @param ghi The iterator. + * @return The value at the current index, or NULL if the + * iterator is done. + */ +void* BLI_ghashIterator_getValue (GHashIterator *ghi); + /** + * Steps the iterator to the next index. + * + * @param ghi The iterator. + */ +void BLI_ghashIterator_step (GHashIterator *ghi); + /** + * Determine if an iterator is done (has reached the end of + * the hash table). + * + * @param ghi The iterator. + * @return True if done, False otherwise. + */ +int BLI_ghashIterator_isDone (GHashIterator *ghi); + +/* *** */ + unsigned int BLI_ghashutil_ptrhash (void *key); int BLI_ghashutil_ptrcmp (void *a, void *b); -- cgit v1.2.3