aboutsummaryrefslogtreecommitdiff
path: root/example_hashmap/old/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'example_hashmap/old/main.c')
-rw-r--r--example_hashmap/old/main.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/example_hashmap/old/main.c b/example_hashmap/old/main.c
new file mode 100644
index 0000000..6c42787
--- /dev/null
+++ b/example_hashmap/old/main.c
@@ -0,0 +1,40 @@
+#include <assert.h>
+#include <stdio.h>
+
+#define MAP_KEY int
+#define MAP_TYPE int
+#define MAP_HASH(a) CONTS_MAP_NO_HASH(a)
+#define MAP_CMP(a, b) ((a) - (b))
+#define MAP_NAME ints
+#include <conts/map.h>
+
+int main()
+{
+ /* heuristic, but if we know how many elements we'll need, we should
+ * give it to the create function. */
+ struct ints ints = ints_create(0);
+ for (int i = 0; i < 1000000; ++i) {
+ ints_insert(&ints, i, i);
+ }
+ assert(ints_len(&ints) == 1000000);
+
+ for (int i = 0; i < 1000000; ++i) {
+ int *v = ints_find(&ints, i);
+ assert(v && *v == i);
+ }
+
+ size_t count = 0;
+ foreach(ints, iter, &ints) {
+ assert(iter->key == iter->data);
+ count++;
+ }
+
+ assert(count == 1000000);
+
+ for (int i = 0; i < 1000000; ++i) {
+ ints_remove(&ints, i);
+ }
+
+ assert(ints_len(&ints) == 0);
+ ints_destroy(&ints);
+}