mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
khash.h (KHASH_FOREACH): a new macro to iterate over khash table
This commit is contained in:
@@ -281,4 +281,24 @@ typedef const char *kh_cstr_t;
|
||||
|
||||
MRB_END_DECL
|
||||
|
||||
/**
|
||||
* Macro for iterating over all elements in a khash.
|
||||
*
|
||||
* Usage:
|
||||
* KHASH_FOREACH(mrb, kh, k) {
|
||||
* // k is the khiter_t iterator
|
||||
* // Access the key with kh_key(kh, k)
|
||||
* // Access the value with kh_val(kh, k) if applicable
|
||||
* // Your code here
|
||||
* }
|
||||
*
|
||||
* @param mrb The mrb_state
|
||||
* @param kh The khash to iterate over
|
||||
* @param k The name to use for the khiter_t iterator variable
|
||||
*/
|
||||
#define KHASH_FOREACH(mrb, kh, k) \
|
||||
if (kh) \
|
||||
for (khiter_t k = kh_begin(kh); k != kh_end(kh); k++) \
|
||||
if (kh_exist(kh, k))
|
||||
|
||||
#endif /* MRUBY_KHASH_H */
|
||||
|
||||
Reference in New Issue
Block a user