aboutsummaryrefslogtreecommitdiff
path: root/sys/libn
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
parent6b739739968a0cc9b4d9909d8f4ffec30f4461dd (diff)
removed buggy qsort header and implemented myself
Diffstat (limited to 'sys/libn')
-rw-r--r--sys/libn/rules.mk4
-rw-r--r--sys/libn/test.c53
2 files changed, 54 insertions, 3 deletions
diff --git a/sys/libn/rules.mk b/sys/libn/rules.mk
index 4731558..ffb41e4 100644
--- a/sys/libn/rules.mk
+++ b/sys/libn/rules.mk
@@ -24,7 +24,7 @@ LIBS_$(d) := $(d)/libn.a
LIBS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(LIBS_$(d)))
LIBS := $(LIBS) $(LIBS_$(d))
-BINS_$(d) := $(d)/test
+BINS_$(d) := $(d)/test $(d)/scratch
BINS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(BINS_$(d)))
BINS := $(BINS) $(BINS_$(d))
@@ -37,7 +37,7 @@ $(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)
$(BINS_$(d)): TCLIBS := $(LIBS_$(d)) $(LIB_DIR)/vendor/libz.a
-$(BINS_$(d)): $(OBJS_$(d)) $(OBJ_DIR)/libn/test.o
+$(BINS_$(d)): $(OBJ_DIR)/libn/scratch.o
$(LINK)
# ---- Pop off stack ----
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()
{