diff options
Diffstat (limited to 'sys/libn/test.c')
-rw-r--r-- | sys/libn/test.c | 53 |
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() { |