Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash: add hash_list_idx() #427

Merged
merged 2 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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