libhl icon indicating copy to clipboard operation
libhl copied to clipboard

ht_foreach_value return remove, will lose item

Open cxm1997 opened this issue 1 year ago • 2 comments

ht_create(65536, 65536, NULL);

TEST_1 remove all item: add 100000 item to hashtable, before ht_foreach_value, ht_count() is 100000 then ht_foreach_value. in callback function return HT_ITERATOR_REMOVE, record entry callback function count is 51261 after, ht_count() is 48739

TEST_2 contine all item: add 100000 item to hashtable, before ht_foreach_value, ht_count() is 100000 then ht_foreach_value, in callback function return HT_ITERATOR_CONTINUE, record entry callback function count is 100000 after, ht_count() is 100000

actually, I want to traverse all items and delete them so, when ht_foreach_value callback return HT_ITERATOR_REMOVE, will lose item.

cxm1997 avatar Jul 02 '24 07:07 cxm1997

use master code to test

cxm1997 avatar Jul 02 '24 07:07 cxm1997

test code at https://gist.github.com/cxm1997/06f99190be5e553f5b476286f333ad14

run result: S0 0 S1 100000 S2 100000 S3 48739 continue 100000 remove 51261

cxm1997 avatar Jul 02 '24 08:07 cxm1997

Thanks! The fix is in 1ab7aec75fdb3e65e11aefbd6ea017e7dcdcd8bf I also added a test which was reproducing the issue before fixing the code in hashtable.c

xant avatar Aug 30 '24 16:08 xant