Skip to content

Commit

Permalink
hash: add hash_list_idx() (#427)
Browse files Browse the repository at this point in the history
Useful for manual hash list iteration.
  • Loading branch information
sreimers authored Jul 8, 2022
1 parent a39ce9d commit 7fd6d14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/re_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void hash_unlink(struct le *le);
struct le *hash_lookup(const struct hash *h, uint32_t key, list_apply_h *ah,
void *arg);
struct le *hash_apply(const struct hash *h, list_apply_h *ah, void *arg);
struct list *hash_list_idx(const struct hash *h, uint32_t i);
struct list *hash_list(const struct hash *h, uint32_t key);
uint32_t hash_bsize(const struct hash *h);
void hash_flush(struct hash *h);
Expand Down
19 changes: 18 additions & 1 deletion src/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,24 @@ struct le *hash_apply(const struct hash *h, list_apply_h *ah, void *arg)


/**
* Return bucket list for a given index
* Return bucket list for a given bucket index
*
* @param h Hashmap table
* @param i Bucket index
*
* @return Bucket list if valid input, otherwise NULL
*/
struct list *hash_list_idx(const struct hash *h, uint32_t i)
{
if (!h || i >= h->bsize)
return NULL;

return &h->bucket[i];
}


/**
* Return bucket list for a given key
*
* @param h Hashmap table
* @param key Hash key
Expand Down

0 comments on commit 7fd6d14

Please sign in to comment.