]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hashmap: Split out iterator.h
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 14 May 2025 20:59:06 +0000 (22:59 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 14 May 2025 22:01:32 +0000 (00:01 +0200)
As preparation for #37344, let's split out iterator.h so we can
avoid including the entirety of hashmap.h where it's not needed.

src/basic/hashmap.h
src/basic/iterator.h [new file with mode: 0644]

index 4aa8fbb0038e270e765c6deb4a49842026ac28b0..52d3f45f0a90dfb83b1f72a586d4cda8bc0a3b3c 100644 (file)
@@ -6,6 +6,7 @@
 #include <stddef.h>
 
 #include "hash-funcs.h"
+#include "iterator.h"
 #include "macro.h"
 
 /*
@@ -35,23 +36,6 @@ typedef struct Set Set;                       /* Stores just keys */
 
 typedef struct IteratedCache IteratedCache;   /* Caches the iterated order of one of the above */
 
-/* Ideally the Iterator would be an opaque struct, but it is instantiated
- * by hashmap users, so the definition has to be here. Do not use its fields
- * directly. */
-typedef struct Iterator {
-        const void *next_key; /* expected value of that entry's key pointer */
-        unsigned idx;         /* index of an entry to be iterated next */
-#if ENABLE_DEBUG_HASHMAP
-        unsigned put_count;   /* hashmap's put_count recorded at start of iteration */
-        unsigned rem_count;   /* hashmap's rem_count in previous iteration */
-        unsigned prev_idx;    /* idx in previous iteration */
-#endif
-} Iterator;
-
-#define _IDX_ITERATOR_FIRST (UINT_MAX - 1)
-#define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL })
-#define ITERATOR_IS_FIRST(i) ((i).idx == _IDX_ITERATOR_FIRST)
-
 /* Macros for type checking */
 #define PTR_COMPATIBLE_WITH_HASHMAP_BASE(h) \
         (__builtin_types_compatible_p(typeof(h), HashmapBase*) || \
diff --git a/src/basic/iterator.h b/src/basic/iterator.h
new file mode 100644 (file)
index 0000000..87cdd3c
--- /dev/null
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+/* Ideally the Iterator would be an opaque struct, but it is instantiated
+ * by hashmap users, so the definition has to be here. Do not use its fields
+ * directly. */
+typedef struct Iterator {
+        const void *next_key; /* expected value of that entry's key pointer */
+        unsigned idx;         /* index of an entry to be iterated next */
+#if ENABLE_DEBUG_HASHMAP
+        unsigned put_count;   /* hashmap's put_count recorded at start of iteration */
+        unsigned rem_count;   /* hashmap's rem_count in previous iteration */
+        unsigned prev_idx;    /* idx in previous iteration */
+#endif
+} Iterator;
+
+#define _IDX_ITERATOR_FIRST (UINT_MAX - 1)
+#define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL })
+#define ITERATOR_IS_FIRST(i) ((i).idx == _IDX_ITERATOR_FIRST)