--- /dev/null
+/*\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.\r
+ *\r
+ * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\r
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#include "cx/map.h"\r
+#include <string.h>\r
+\r
+// <editor-fold desc="empty map implementation">\r
+\r
+static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) {\r
+ // this is a noop, but MUST be implemented\r
+}\r
+\r
+static void *cx_empty_map_get(\r
+ __attribute__((__unused__)) CxMap const *map,\r
+ __attribute__((__unused__)) CxHashKey key\r
+) {\r
+ return NULL;\r
+}\r
+\r
+static bool cx_empty_map_iter_valid(__attribute__((__unused__)) void const *iter) {\r
+ return false;\r
+}\r
+\r
+static CxIterator cx_empty_map_iterator(\r
+ struct cx_map_s const *map,\r
+ __attribute__((__unused__)) enum cx_map_iterator_type type\r
+) {\r
+ CxIterator iter = {0};\r
+ iter.src_handle = map;\r
+ iter.base.valid = cx_empty_map_iter_valid;\r
+ return iter;\r
+}\r
+\r
+static struct cx_map_class_s cx_empty_map_class = {\r
+ cx_empty_map_noop,\r
+ cx_empty_map_noop,\r
+ NULL,\r
+ cx_empty_map_get,\r
+ NULL,\r
+ cx_empty_map_iterator\r
+};\r
+\r
+CxMap cx_empty_map = {\r
+ NULL,\r
+ NULL,\r
+ 0,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ NULL,\r
+ false,\r
+ &cx_empty_map_class\r
+};\r
+\r
+CxMap *const cxEmptyMap = &cx_empty_map;\r
+\r
+// </editor-fold>\r
+\r
+CxMutIterator cxMapMutIteratorValues(CxMap *map) {\r
+ CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);\r
+ it.base.mutating = true;\r
+\r
+ // we know the iterators share the same memory layout\r
+ CxMutIterator iter;\r
+ memcpy(&iter, &it, sizeof(CxMutIterator));\r
+ return iter;\r
+}\r
+\r
+CxMutIterator cxMapMutIteratorKeys(CxMap *map) {\r
+ CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);\r
+ it.base.mutating = true;\r
+\r
+ // we know the iterators share the same memory layout\r
+ CxMutIterator iter;\r
+ memcpy(&iter, &it, sizeof(CxMutIterator));\r
+ return iter;\r
+}\r
+\r
+CxMutIterator cxMapMutIterator(CxMap *map) {\r
+ CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);\r
+ it.base.mutating = true;\r
+\r
+ // we know the iterators share the same memory layout\r
+ CxMutIterator iter;\r
+ memcpy(&iter, &it, sizeof(CxMutIterator));\r
+ return iter;\r
+}\r