1 #include <stdlib.h> //malloc
2 #include <stdio.h> //print
3 #include <string.h> //memcpy
4 #include "../ston/ston.h"
6 /* ansi terminal colors */
8 #define GREEN "\x1b[32m"
9 #define YELLOW "\x1b[33m"
10 #define BLUE "\x1b[34m"
11 #define MAGENTA "\x1b[35m"
12 #define CYAN "\x1b[36m"
13 #define CLRC "\x1b[0m" //clear current color
14 #define CLRCN CLRC"\n"
16 #define print_val(val) do { \
17 for (i = 0; i < (size_t)columns; i++) \
18 printf("["YELLOW"%x"CLRC"]",val[i]); \
22 #define check_ht(_HT) \
24 { fprintf(stderr,RED"Could not allocate ht32"CLRCN); \
28 printf("ht_size: [units:%i][bytes:%li]\n",ston_ht_size(ht),ston_ht32_size(ht)); \
31 int main(int argc, char* argv[])
33 uint32_t* htval
, previous_val
;
34 uint32_t val
[255], key
;
40 printf("up2pow [5] = [%i]\n",ston_up2pow(5));
41 for (i
= 0; i
< 255; i
+= 7)
42 printf("trailing0 [%X] = [%x]\n",(uint32_t)i
,ston_trailing0(i
));
46 ht
= ston_ht32_new(columns
,elements
,0,malloc
);
51 printf("ht32_insertx: [%x] = ", key
);
53 ston_ht32_insertx(ht
,key
,val
,0,columns
);
55 htval
= ston_ht32_row(ht
,key
);
56 printf("Read value [%x] matches: %s"CLRCN
, htval
[idx
],
57 (htval
[idx
] == val
[idx
]) ? GREEN
"PASS" : RED
"FAIL");
60 previous_val
= ston_ht32_insert(ht
,key
,1,val
[1]);
61 printf("ht32_insert: [%x] = ", key
);
63 printf("Previous value [%x] matches [5]: %s"CLRCN
, previous_val
,
64 (previous_val
== 0x5) ? GREEN
"PASS" : RED
"FAIL");
70 ht
= ston_ht32_new(columns
,elements
,0,malloc
);
72 printf("Filling hashtable with entries\n");
73 for(key
= 0xCEED; elements
--; key
*= 7)
75 for(i
= 1; i
< columns
; i
++)
77 ston_ht32_insertx(ht
,key
,val
,0,columns
);
79 printf("Reading entries\n");
81 for(key
= 0xCEED; elements
--; key
*= 7)
82 { htval
= ston_ht32_row(ht
,key
);
83 printf("[%s%x"CLRC
"]",(*htval
== key
) ? GREEN
: RED
,*htval
);
84 for(i
= 1; i
< columns
; i
++)
85 printf("[%s%x"CLRC
"]",(htval
[i
] == (uint32_t)(i
* key
)) ? GREEN
: RED
,htval
[i
]);
88 int max_capacity
= ston_up2pow(20 << 1) - 20;
89 printf("Overfilling hashtable with %i entries\n", max_capacity
);
90 int cap
= max_capacity
;
91 for(key
= 0xCEED2; cap
--; key
*= 13)
93 for(i
= 1; i
< columns
; i
++)
95 ston_ht32_insertx(ht
,key
,val
,0,columns
);
97 printf("Reading entries\n");
99 for(key
= 0xCEED2; cap
--; key
*= 13)
100 { htval
= ston_ht32_row(ht
,key
);
101 printf("[%s%x"CLRC
"]",(*htval
== key
) ? GREEN
: RED
,*htval
);
102 for(i
= 1; i
< columns
; i
++)
103 printf("[%s%x"CLRC
"]",(htval
[i
] == (uint32_t)(key
* -i
)) ? GREEN
: RED
,htval
[i
]);