limit size of hash?

46 views
Skip to first unread message

zen...@gmail.com

unread,
Apr 24, 2018, 7:03:19 PM4/24/18
to uthash
Is there a way to limit the number of items in the hash perhaps with some sort of replacement scheme once it fills up?

Thanks,
-Erin

silvioprog

unread,
Apr 24, 2018, 7:18:47 PM4/24/18
to uth...@googlegroups.com
Hi Erin.

You can do it easily using your own list handle. For example, consider the following line in the code of a library I maintain:


I could specify a limit by adding the following two bold lines to my handle "map":

...

53.    if (!map || !name || !val)
54.        return -EINVAL;
55.    if (map->count > count_limit)
56.        return -ELIMIT;
57.    pair = bk_alloc(sizeof(struct bk_strmap));

...

So, add a limit flag to your map handle. ☺
--
Silvio Clécio

zen...@gmail.com

unread,
Apr 25, 2018, 5:33:30 PM4/25/18
to uthash
Thanks, Silvio. Adding a count test (against the HASH_COUNT macro) to an add wrapper function makes sense, just wanted to make sure there wasn't anything built in first. The trick now will be to handle such cases by freeing up room in the hash table, preferably starting with the oldest records.
Reply all
Reply to author
Forward
0 new messages