aboutsummaryrefslogtreecommitdiff
path: root/test/104_h48set/h48set_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/104_h48set/h48set_tests.c')
-rw-r--r--test/104_h48set/h48set_tests.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/test/104_h48set/h48set_tests.c b/test/104_h48set/h48set_tests.c
index 97811da..d9310a9 100644
--- a/test/104_h48set/h48set_tests.c
+++ b/test/104_h48set/h48set_tests.c
@@ -15,6 +15,7 @@ void h48set_destroy(h48set_t *);
15int64_t h48set_lookup(h48set_t *, int64_t); 15int64_t h48set_lookup(h48set_t *, int64_t);
16void h48set_insert(h48set_t *, int64_t); 16void h48set_insert(h48set_t *, int64_t);
17bool h48set_contains(h48set_t *, int64_t); 17bool h48set_contains(h48set_t *, int64_t);
18int64_t h48set_save(h48set_t *, int64_t *);
18 19
19int compare(const void *x, const void *y) { 20int compare(const void *x, const void *y) {
20 int64_t a = *(int64_t *)x; 21 int64_t a = *(int64_t *)x;
@@ -31,39 +32,33 @@ int64_t readl(void) {
31} 32}
32 33
33void run(void) { 34void run(void) {
34 bool f;
35 h48set_t set; 35 h48set_t set;
36 int64_t n, i, j, capacity, mod, *a, u; 36 int64_t n, i, k, capacity, mod, *a, *b;
37 37
38 capacity = readl(); 38 capacity = readl();
39 mod = readl(); 39 mod = readl();
40 n = readl(); 40 n = readl();
41 41
42 a = malloc(n * sizeof(int64_t)); 42 a = malloc(n * sizeof(int64_t));
43 b = malloc(n * sizeof(int64_t));
43 for (i = 0; i < n; i++) 44 for (i = 0; i < n; i++)
44 a[i] = readl(); 45 a[i] = readl();
45 46
46 /* Count unique elements */
47 u = 0;
48 for (i = 0; i < n; i++) {
49 for (j = 0, f = true; j < i; j++)
50 f = f && a[i] != a[j];
51 u += f;
52 }
53
54 h48set_create(&set, capacity, mod); 47 h48set_create(&set, capacity, mod);
55 for (i = 0; i < n; i++) 48 for (i = 0; i < n; i++)
56 h48set_insert(&set, a[i]); 49 h48set_insert(&set, a[i]);
57 50
58 for (i = 0, j = 0; i < set.capacity; i++) 51 k = h48set_save(&set, b);
59 if (set.table[i] != -1) 52 qsort(b, k, sizeof(int64_t), compare);
60 a[j++] = set.table[i];
61 qsort(a, j, sizeof(int64_t), compare);
62 53
63 printf("%" PRId64 "\n", set.n); 54 printf("%" PRId64 "\n", k);
64 for (i = 0; i < j; i++) 55 for (i = 0; i < k; i++)
65 printf("%" PRId64 "\n", a[i]); 56 printf("%" PRId64 "\n", b[i]);
57 for (i = 0; i < n; i++)
58 if (!h48set_contains(&set, a[i]))
59 printf("Set does not contain %" PRId64 "\n", a[i]);
66 60
67 h48set_destroy(&set); 61 h48set_destroy(&set);
68 free(a); 62 free(a);
63 free(b);
69} 64}

Generated with cgit - Back to sebastiano.tronto.net