summaryrefslogtreecommitdiff
path: root/lib/hmapx.h
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-04-07 17:10:48 -0700
committerBen Pfaff <blp@nicira.com>2011-05-04 10:27:20 -0700
commitf4ac3fc104d83edce7d3f2410a7b02cb56dd0ac2 (patch)
treee09d9393cfe708dd5f017426c6103639b3859c50 /lib/hmapx.h
parentf8ddccd2852c10758854ac18c7d440cca68e3964 (diff)
downloadopenvswitch-f4ac3fc104d83edce7d3f2410a7b02cb56dd0ac2.tar.gz
hmapx: New data structure.
Diffstat (limited to 'lib/hmapx.h')
-rw-r--r--lib/hmapx.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/hmapx.h b/lib/hmapx.h
new file mode 100644
index 000000000..226255dce
--- /dev/null
+++ b/lib/hmapx.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011 Nicira Networks.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HMAPX_H
+#define HMAPX_H
+
+#include "hmap.h"
+
+struct hmapx_node {
+ struct hmap_node hmap_node;
+ void *data;
+};
+
+/* A set of "void *" pointers. */
+struct hmapx {
+ struct hmap map;
+};
+
+#define HMAPX_INITIALIZER(HMAPX) { HMAP_INITIALIZER(&(HMAPX)->map) }
+
+/* Basics. */
+void hmapx_init(struct hmapx *);
+void hmapx_destroy(struct hmapx *);
+void hmapx_clone(struct hmapx *, const struct hmapx *);
+void hmapx_swap(struct hmapx *, struct hmapx *);
+void hmapx_moved(struct hmapx *);
+
+/* Count. */
+bool hmapx_is_empty(const struct hmapx *);
+size_t hmapx_count(const struct hmapx *);
+
+/* Insertion. */
+struct hmapx_node *hmapx_add(struct hmapx *, void *);
+void hmapx_add_assert(struct hmapx *, void *);
+
+/* Deletion. */
+void hmapx_clear(struct hmapx *);
+void hmapx_delete(struct hmapx *, struct hmapx_node *);
+bool hmapx_find_and_delete(struct hmapx *, const void *);
+void hmapx_find_and_delete_assert(struct hmapx *, const void *);
+
+/* Search. */
+struct hmapx_node *hmapx_find(const struct hmapx *, const void *);
+bool hmapx_contains(const struct hmapx *, const void *);
+bool hmapx_equals(const struct hmapx *, const struct hmapx *);
+
+/* Iteration. */
+
+/* Iterates through every hmapx_node in HMAPX. */
+#define HMAPX_FOR_EACH(NODE, HMAPX) \
+ HMAP_FOR_EACH(NODE, hmap_node, &(HMAPX)->map)
+
+/* Safe when NODE may be freed (not needed when NODE may be removed from the
+ * hash map but its members remain accessible and intact). */
+#define HMAPX_FOR_EACH_SAFE(NODE, NEXT, HMAPX) \
+ HMAP_FOR_EACH_SAFE(NODE, NEXT, hmap_node, &(HMAPX)->map)
+
+#endif /* hmapx.h */