From 77c4bb10c6c7c723628d35f46a24afa5950fdf4f Mon Sep 17 00:00:00 2001 From: Al Date: Fri, 9 Oct 2015 11:51:32 -0400 Subject: [PATCH] [utils] Adding kh_foreach_key --- src/klib/khash.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/klib/khash.h b/src/klib/khash.h index b068999f..e4e25fa5 100644 --- a/src/klib/khash.h +++ b/src/klib/khash.h @@ -523,6 +523,20 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key) code; \ } } +/*! @function + @abstract Iterate over the keys in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @param vvar Variable to which key will be assigned + @param code Block of code to execute + */ +#define kh_foreach_key(h, kvar, code) { khint_t __i; \ + for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \ + if (!kh_exist(h,__i)) continue; \ + (kvar) = kh_key(h,__i); \ + code; \ + } } + + /*! @function @abstract Iterate over the values in the hash table @param h Pointer to the hash table [khash_t(name)*]