X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fsorter%2Fsort-test.c;h=f8384a7554a144eba31211e414ab1fb2b282f037;hb=959566090f98dd31eaa67d3d5959b641e5fe902b;hp=17c6e7f0d09c72b7aeeed71adf021df7b8d9e06c;hpb=3366235d970c8516d4e1bc8be66c522ab106801b;p=libucw.git diff --git a/ucw/sorter/sort-test.c b/ucw/sorter/sort-test.c index 17c6e7f0..f8384a75 100644 --- a/ucw/sorter/sort-test.c +++ b/ucw/sorter/sort-test.c @@ -7,15 +7,16 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/getopt.h" -#include "ucw/conf.h" -#include "ucw/fastbuf.h" -#include "ucw/ff-binary.h" -#include "ucw/hashfunc.h" -#include "ucw/md5.h" -#include "ucw/string.h" -#include "ucw/prime.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -33,7 +34,7 @@ /*** Time measurement ***/ static timestamp_t timer; -static uns test_id; +static uint test_id; static void start(void) @@ -63,17 +64,17 @@ struct key1 { #define SORT_INT(k) (k).x #define SORT_DELETE_INPUT 0 -#include "ucw/sorter/sorter.h" +#include static void test_int(int mode, u64 size) { - uns N = size ? nextprime(MIN(size/4, 0xffff0000)) : 0; - uns K = N/4*3; + uint N = size ? nextprime(MIN(size/4, 0xffff0000)) : 0; + uint K = N/4*3; msg(L_INFO, ">>> Integers (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N); struct fastbuf *f = bopen_tmp(65536); - for (uns i=0; icnt += k[i]->cnt; bwrite(f, k[0], sizeof(struct key2)); } @@ -112,23 +113,23 @@ static inline void s2_write_merged(struct fastbuf *f, struct key2 **k, void **d #define SORT_UNIFY #define SORT_INT(k) (k).x -#include "ucw/sorter/sorter.h" +#include static void test_counted(int mode, u64 size) { u64 items = size / sizeof(struct key2); - uns mult = 2; + uint mult = 2; while (items/(2*mult) > 0xffff0000) mult++; - uns N = items ? nextprime(items/(2*mult)) : 0; - uns K = N/4*3; + uint N = items ? nextprime(items/(2*mult)) : 0; + uint K = N/4*3; msg(L_INFO, ">>> Counted integers (%s, N=%u, mult=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N, mult); struct fastbuf *f = bopen_tmp(65536); - for (uns m=0; mhash[0]; } @@ -180,10 +181,10 @@ static inline uns s3_hash(struct key3 *x) #define SORT_OUTPUT_FB #define SORT_HASH_BITS 32 -#include "ucw/sorter/sorter.h" +#include static void -gen_hash_key(int mode, struct key3 *k, uns i) +gen_hash_key(int mode, struct key3 *k, uint i) { k->i = i; k->payload[0] = 7*i + 13; @@ -212,13 +213,13 @@ gen_hash_key(int mode, struct key3 *k, uns i) static void test_hashes(int mode, u64 size) { - uns N = MIN(size / sizeof(struct key3), 0xffffffff); + uint N = MIN(size / sizeof(struct key3), 0xffffffff); msg(L_INFO, ">>> Hashes (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N); struct key3 k, lastk; struct fastbuf *f = bopen_tmp(65536); - uns hash_sum = 0; - for (uns i=0; ilen, y->len); + uint l = MIN(x->len, y->len); int c = memcmp(x->s, y->s, l); if (c) return c; @@ -288,13 +289,13 @@ static inline void s4_write_key(struct fastbuf *f, struct key4 *x) #define SORT_INPUT_FB #define SORT_OUTPUT_FB -#include "ucw/sorter/sorter.h" +#include #define s4b_compare s4_compare #define s4b_read_key s4_read_key #define s4b_write_key s4_write_key -static inline uns s4_data_size(struct key4 *x) +static inline uint s4_data_size(struct key4 *x) { return x->len ? (x->s[0] ^ 0xad) : 0; } @@ -306,18 +307,18 @@ static inline uns s4_data_size(struct key4 *x) #define SORT_INPUT_FB #define SORT_OUTPUT_FB -#include "ucw/sorter/sorter.h" +#include static void gen_key4(struct key4 *k) { k->len = random_max(KEY4_MAX); - for (uns i=0; ilen; i++) + for (uint i=0; ilen; i++) k->s[i] = random(); } static void -gen_data4(byte *buf, uns len, uns h) +gen_data4(byte *buf, uint len, uint h) { while (len--) { @@ -327,23 +328,23 @@ gen_data4(byte *buf, uns len, uns h) } static void -test_strings(uns mode, u64 size) +test_strings(uint mode, u64 size) { - uns avg_item_size = KEY4_MAX/2 + 4 + (mode ? 128 : 0); - uns N = MIN(size / avg_item_size, 0xffffffff); + uint avg_item_size = KEY4_MAX/2 + 4 + (mode ? 128 : 0); + uint N = MIN(size / avg_item_size, 0xffffffff); msg(L_INFO, ">>> Strings %s(N=%u)", (mode ? "with data " : ""), N); srand(1); struct key4 k, lastk; byte buf[256], buf2[256]; - uns sum = 0; + uint sum = 0; struct fastbuf *f = bopen_tmp(65536); - for (uns i=0; i -static void s5_write_merged(struct fastbuf *f, struct key5 **keys, void **data, uns n, void *buf) +static void s5_write_merged(struct fastbuf *f, struct key5 **keys, void **data, uint n, void *buf) { u32 *a = buf; - uns m = 0; - for (uns i=0; icnt); m += keys[i]->cnt; } - s5m_sort(m, a); + s5m_sort(a, m); keys[0]->cnt = m; bwrite(f, keys[0], sizeof(struct key5)); bwrite(f, a, 4*m); } -static void s5_copy_merged(struct key5 **keys, struct fastbuf **data, uns n, struct fastbuf *dest) +static void s5_copy_merged(struct key5 **keys, struct fastbuf **data, uint n, struct fastbuf *dest) { u32 k[n]; - uns m = 0; - for (uns i=0; icnt; @@ -441,8 +440,8 @@ static void s5_copy_merged(struct key5 **keys, struct fastbuf **data, uns n, str bwrite(dest, &key, sizeof(key)); while (key.cnt--) { - uns b = 0; - for (uns i=1; i static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize) { - uns max = MIN(bufsize/sizeof(struct s5_pair), 0xffffffff); + uint max = MIN(bufsize/sizeof(struct s5_pair), 0xffffffff); struct s5_pair *a = buf; - uns n = 0; + uint n = 0; while (n #define SORT_KEY_REGULAR struct key5 #define SORT_PREFIX(x) s5b_##x @@ -511,12 +510,12 @@ static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize) #define s5b_write_merged s5_write_merged #define s5b_copy_merged s5_copy_merged -#include "ucw/sorter/sorter.h" +#include static void -test_graph(uns mode, u64 size) +test_graph(uint mode, u64 size) { - uns N = 3; + uint N = 3; while ((u64)N*(N+2)*4 < size) N = nextprime(N); if (!size) @@ -549,18 +548,18 @@ test_graph(uns mode, u64 size) stop(); SORT_XTRACE(2, "Verifying"); - uns c = bgetl(f); + uint c = bgetl(f); ASSERT(c == 0xfeedcafe); - for (uns i=0; i static void test_int64(int mode, u64 size) @@ -611,7 +610,7 @@ test_int64(int mode, u64 size) /*** Main ***/ static void -run_test(uns i, u64 size) +run_test(uint i, u64 size) { test_id = i; switch (i) @@ -658,7 +657,7 @@ main(int argc, char **argv) log_init(NULL); int c; u64 size = 10000000; - uns t = ~0; + uint t = ~0; while ((c = cf_getopt(argc, argv, CF_SHORT_OPTS "d:s:t:v", CF_NO_LONG_OPTS, NULL)) >= 0) switch (c) @@ -697,7 +696,7 @@ main(int argc, char **argv) if (optind != argc) goto usage; - for (uns i=0; i