commit 852a21d: [Minor] Add utility to iterate over values by pointer and keys

Vsevolod Stakhov vsevolod at rspamd.com
Mon May 8 17:56:04 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-05-08 18:43:36 +0100
URL: https://github.com/rspamd/rspamd/commit/852a21d68ec2850f95b74a829639264ddf264f30 (HEAD -> master)

[Minor] Add utility to iterate over values by pointer and keys

---
 contrib/libucl/khash.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/contrib/libucl/khash.h b/contrib/libucl/khash.h
index 3e580011d..0b8a4356d 100644
--- a/contrib/libucl/khash.h
+++ b/contrib/libucl/khash.h
@@ -583,6 +583,14 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
 		code;												\
 	} }
 
+#define kh_foreach_key_value_ptr(h, kvar, pvvar, 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);								\
+		(pvvar) = &kh_val(h,__i);							\
+		code;												\
+	} }
+
 #define kh_foreach_key(h, kvar, code) {						\
 	khint_t __i;											\
 	for (__i = kh_begin(h); __i != kh_end(h); ++__i) {		\


More information about the Commits mailing list