You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has the downside of allocating an array and copying the keys, just to discard it it right after.
The fact that mrb_hash_tbl is exposed as a public API suggests that it is fine to access directly the kh_ht. This would allow to iterate without copying by using kh_begin and kh_end. The problem is that they do not work because these macros rely on the declaration of struct kh_ht which is private in hash.c. In that case, I wonder if the kh_ht is really mean to be public?
If yes, can I move KHASH_DECLARE to khash.h so it is usable from outside?
If no, I guess mrb_hash_tbl should not be public at all. In that case, what do you think of adding functions similar to these to the Hash API?
/* callback can break loop with return FALSE */voidmrb_each_with_index(
structmrb_state*mrb,
mrb_valuehash_or_array,
int (*callback)(mrb_valueindex, mrb_valuevalue));
It may cause serious problems if the hash is modified during the iteration. So I am not positive about providing public API to iterate over hashes. Instead I'd rather move KHASH_DECLARE to mruby/hash.h.
I currently use
mrb_hash_keys
to iterate over a hash like thisThis has the downside of allocating an array and copying the keys, just to discard it it right after.
The fact that mrb_hash_tbl is exposed as a public API suggests that it is fine to access directly the
kh_ht
. This would allow to iterate without copying by usingkh_begin and kh_end
. The problem is that they do not work because these macros rely on the declaration ofstruct kh_ht
which is private inhash.c
. In that case, I wonder if thekh_ht
is really mean to be public?KHASH_DECLARE
tokhash.h
so it is usable from outside?mrb_hash_tbl
should not be public at all. In that case, what do you think of adding functions similar to these to the Hash API?Thank you.
The text was updated successfully, but these errors were encountered: