Change stats print places. Inc keys count.

This commit is contained in:
Darko 2015-03-21 20:13:45 +01:00
parent 50b3672d36
commit 3cf1900929

14
main.c
View file

@ -5,7 +5,7 @@
#include "x.h" #include "x.h"
#define MAXBUF 80 #define MAXBUF 80
#define KEYCNT 10000 #define KEYCNT 1000000
int dodebug = 1; int dodebug = 1;
@ -76,7 +76,6 @@ int main(int argc, char **argv)
key = random() % KEYCNT; key = random() % KEYCNT;
keys[i] = key; keys[i] = key;
res = sl_add(&sl, key, NULL); res = sl_add(&sl, key, NULL);
sl_stat_print(&sl);
switch(res) { switch(res) {
case SL_ADD_NEW: case SL_ADD_NEW:
++cntnew; ++cntnew;
@ -91,6 +90,7 @@ int main(int argc, char **argv)
} }
printf("added %d new keys, %d same keys, list len: %lu\n", printf("added %d new keys, %d same keys, list len: %lu\n",
cntnew, cntsame, sl.len); cntnew, cntsame, sl.len);
sl_stat_print(&sl);
dodebug = 1; dodebug = 1;
sl_print(&sl); sl_print(&sl);
dodebug = 0; dodebug = 0;
@ -98,20 +98,23 @@ int main(int argc, char **argv)
for (i = 0; i < KEYCNT; ++i) { for (i = 0; i < KEYCNT; ++i) {
key = keys[i]; key = keys[i];
x = sl_find(&sl, key); x = sl_find(&sl, key);
sl_stat_print(&sl);
if (!x) { if (!x) {
failed = 1; failed = 1;
break; ++cntnew;
} else {
++cntsame;
} }
} }
if (failed) { if (failed) {
fatal("find failed, report bug\n"); fatal("find failed, report bug\n");
} }
printf("should find %d keys but didn't, %d found keys, list len: %lu\n",
cntnew, cntsame, sl.len);
sl_stat_print(&sl);
cntnew = cntsame = 0; cntnew = cntsame = 0;
for (i = 0; i < KEYCNT; ++i) { for (i = 0; i < KEYCNT; ++i) {
key = keys[i]; key = keys[i];
res = sl_remove(&sl, key); res = sl_remove(&sl, key);
sl_stat_print(&sl);
switch (res) { switch (res) {
case 0: case 0:
++cntsame; ++cntsame;
@ -132,6 +135,7 @@ int main(int argc, char **argv)
} }
printf("removed %d keys, %d same keys, list len: %lu\n", printf("removed %d keys, %d same keys, list len: %lu\n",
cntnew, cntsame, sl.len); cntnew, cntsame, sl.len);
sl_stat_print(&sl);
sl_free(&sl); sl_free(&sl);
return 0; return 0;