summaryrefslogtreecommitdiffstats
path: root/clib/test/map.c
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@us.ibm.com>2014-06-30 22:10:16 -0500
committerPatrick Williams <iawillia@us.ibm.com>2014-07-02 22:49:29 -0500
commitbf4630076762d9c20c16c80c1c791f352b046dd1 (patch)
treeefc67bad010a28fd1abf5aeeefda2a969514fd97 /clib/test/map.c
downloadffs-bf4630076762d9c20c16c80c1c791f352b046dd1.tar.gz
ffs-bf4630076762d9c20c16c80c1c791f352b046dd1.zip
Port FFS tools over from Building Block repository.
Diffstat (limited to 'clib/test/map.c')
-rw-r--r--clib/test/map.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/clib/test/map.c b/clib/test/map.c
new file mode 100644
index 0000000..2501a32
--- /dev/null
+++ b/clib/test/map.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <clib/assert.h>
+#include <clib/slab.h>
+#include <clib/type.h>
+#include <clib/map.h>
+
+struct data {
+ map_node_t node;
+ int i;
+ float f;
+};
+typedef struct data data_t;
+
+int main (void) {
+ slab_t s = INIT_SLAB;
+ slab_init(&s, "my_slab", sizeof(data_t), 0);
+
+ int compare(const int i1, const int i2) {
+ return i1 - i2;
+ }
+
+ map_t m;
+ map_init(&m, (compare_f)compare);
+
+ int i;
+ for (i=0; i<100; i++) {
+ data_t * d = (data_t *)slab_alloc(&s);
+
+ printf("i[%d]\n", i);
+
+ d->i = i;
+ d->f = (float)i;
+
+ map_node_init(&d->node, (const void *)(d->i));
+ map_insert(&m, &d->node);
+ }
+
+#if 1
+ i = 6;
+ map_node_t * n = map_find(&m, (const void *)(i));
+ map_remove(&m, n);
+ n = map_find(&m, (const void *)i);
+
+ i = 2;
+ map_find(&m, (const void *)i);
+ i = 8;
+ map_find(&m, (const void *)i);
+#endif
+
+ map_dump(&m, stdout);
+ slab_delete(&s);
+
+ return 0;
+}
+
OpenPOWER on IntegriCloud