-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
119 lines (63 loc) · 2.32 KB
/
main.cc
File metadata and controls
119 lines (63 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <assert.h>
#include "hash.h"
#define SIZE_SEQ(seq) (sizeof seq / sizeof seq[0])
static uint64_t hash_function_1(uint64_t const* v, size_t n) {
uint64_t hash = 0;
for (size_t k = 0; k < n; ++k) hash ^= v[k];
return hash;
}
static uint64_t hash_function_2(uint64_t const* v, size_t n) {
uint64_t hash = 0;
for (size_t k = 0; k < n; ++k) hash += v[k];
return hash;
}
int main() {
unsigned long id_1, id_2;
uint64_t const seq_1[] = {0, 1, 3000, 150, 25};
uint64_t const seq_2[] = {25, 3000, 150, 1, 0};
uint64_t const seq_3[] = {1, 0, 250};
id_1 = hash_create(hash_function_1);
assert(hash_size(id_1) == 0);
assert(hash_insert(id_1, seq_1, SIZE_SEQ(seq_1)));
assert(hash_size(id_1) == 1);
assert(hash_insert(id_1, seq_2, SIZE_SEQ(seq_2)));
assert(hash_size(id_1) == 2);
assert(!hash_insert(id_1, seq_1, SIZE_SEQ(seq_1)));
assert(hash_size(id_1) == 2);
assert(!hash_insert(id_1, NULL, 0));
assert(!hash_insert(id_1, NULL, 1));
assert(!hash_insert(id_1, seq_3, 0));
assert(hash_test(id_1, seq_2, SIZE_SEQ(seq_2)));
assert(!hash_test(id_1, seq_3, SIZE_SEQ(seq_3)));
assert(!hash_test(id_1, NULL, 0));
assert(!hash_test(id_1, NULL, 1));
assert(!hash_test(id_1, seq_1, 0));
assert(!hash_test(id_1, seq_1, SIZE_SEQ(seq_1) - 1));
assert(hash_remove(id_1, seq_1, SIZE_SEQ(seq_1)));
assert(hash_size(id_1) == 1);
assert(hash_insert(id_1, seq_3, SIZE_SEQ(seq_3)));
assert(hash_size(id_1) == 2);
assert(!hash_remove(id_1, seq_1, SIZE_SEQ(seq_1)));
assert(!hash_remove(id_1, NULL, 0));
assert(!hash_remove(id_1, NULL, 1));
assert(!hash_remove(id_1, seq_2, 0));
id_2 = hash_create(hash_function_2);
assert(hash_insert(id_2, seq_2, SIZE_SEQ(seq_2)));
assert(hash_insert(id_2, seq_3, SIZE_SEQ(seq_3)));
hash_clear(id_1);
assert(hash_size(id_1) == 0);
assert(hash_remove(id_2, seq_2, SIZE_SEQ(seq_2)));
assert(hash_size(id_2) == 1);
assert(hash_remove(id_2, seq_3, SIZE_SEQ(seq_3)));
assert(hash_size(id_2) == 0);
hash_clear(id_2);
assert(hash_size(id_2) == 0);
hash_delete(id_1);
assert(!hash_insert(id_1, seq_1, SIZE_SEQ(seq_1)));
assert(!hash_remove(id_1, seq_1, SIZE_SEQ(seq_1)));
assert(!hash_test(id_1, seq_1, SIZE_SEQ(seq_1)));
hash_clear(id_1);
assert(hash_size(id_1) == 0);
hash_delete(id_1);
hash_delete(id_2);
}