Add iterator API
This commit is contained in:
@@ -39,6 +39,15 @@ struct UHTable {
|
||||
struct UHNode **buckets;
|
||||
};
|
||||
|
||||
/** Iterator for the iterator API */
|
||||
struct UHIter {
|
||||
//internal fields
|
||||
struct UHNode **it;
|
||||
struct UHNode **next;
|
||||
size_t cur_bucket;
|
||||
size_t cur_hash;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a hash table.
|
||||
* @param table hash table to initialize
|
||||
@@ -246,4 +255,32 @@ void uc_htable_remove(struct UHTable *table, struct UHNode *node);
|
||||
int uc_htable_resize(struct UHTable *table, size_t buckets);
|
||||
|
||||
|
||||
/** Get the first node with the given hash.
|
||||
*
|
||||
* @param table table
|
||||
* @param iter opaque iterator
|
||||
* @param hash hash to find
|
||||
* @return the first node found or NULL
|
||||
*/
|
||||
struct UHNode *uc_htable_iter_first_hash(struct UHTable *table,
|
||||
struct UHIter *iter, size_t hash);
|
||||
/** Get the next node with the given hash, the iterator
|
||||
* must previously have been passed to uc_htable_iter_first_hash
|
||||
* which returned a non-NULL value
|
||||
*
|
||||
* @param iter opaque iterator
|
||||
* @return the next node found or NULL
|
||||
*/
|
||||
struct UHNode *uc_htable_iter_next_hash(struct UHIter *iter);
|
||||
|
||||
/** Remove the node pointed to by the current iterator,
|
||||
* uc_htable_iter_first_hash or uc_htable_iter_next_hash
|
||||
* must previously have returned non-NULL. The node
|
||||
* returned by the previous call is the one removed.
|
||||
* It is safe to continue iterating after this
|
||||
*
|
||||
* @param iter indicated node to remove
|
||||
*/
|
||||
void uc_htable_iter_remove(struct UHIter *iter);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user