aboutsummaryrefslogtreecommitdiff
path: root/sys/libn/test.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-05-03 20:20:22 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-05-03 20:20:22 -0700
commit4b2ea2ca00eea7feea036b7642c0c1443b8f77a1 (patch)
tree5cdd635bd8240a6857258a056e3932e00966bfff /sys/libn/test.c
parent6b739739968a0cc9b4d9909d8f4ffec30f4461dd (diff)
removed buggy qsort header and implemented myself
Diffstat (limited to 'sys/libn/test.c')
-rw-r--r--sys/libn/test.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/sys/libn/test.c b/sys/libn/test.c
index 3a21a71..973245f 100644
--- a/sys/libn/test.c
+++ b/sys/libn/test.c
@@ -1,5 +1,6 @@
#include <u.h>
#include <libn.h>
+#include <libn/macro/map.h>
#include <time.h>
@@ -122,7 +123,7 @@ error
test·sort()
{
clock_t t;
- int i, test[1000000];
+ int i, test[10000];
for (i = 0; i < arrlen(test); i++) {
test[i] = rand();
}
@@ -154,6 +155,56 @@ test·sort()
return 0;
}
+#define HASH(str) hash_string(str)
+#define EQUAL(str, str2) (str == str2)
+
+typedef struct Map
+{
+ MAP_STRUCT_BODY(byte*, float)
+} Map;
+
+Map*
+makemap(mem·Allocator heap, void* h)
+{
+ MAP_MAKE(Map);
+}
+
+void
+mapfree(Map *map)
+{
+ MAP_FREE(map);
+}
+
+void
+mapreset(Map *map)
+{
+ MAP_RESET(map);
+}
+
+double
+mapget(Map *map, byte *key)
+{
+ MAP_GET(map, key, HASH, EQUAL);
+}
+
+static
+error
+mapresize(Map *map, int n)
+{
+ MAP_GROW(map, byte*, float, n, HASH);
+}
+
+static
+int
+mapput(Map *map, byte *key, float val, error *err)
+{
+ MAP_PUT(map, key, val, HASH, EQUAL, mapresize, err);
+}
+
+
+#undef HASH
+#undef EQUAL
+
error
main()
{