File: mhash_body.c

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (184 lines) | stat: -rw-r--r-- 1,993 bytes parent folder | download | duplicates (5)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#define set(x) ({							\
	k = put(x);							\
	val(k) = (x) << 1;						\
})


#define rm(x) ({							\
	mh_int_t k = get(x);						\
	del(k);								\
})

#define tst(x) ({							\
	mh_int_t k = get((x));						\
	fail_unless(k != mh_end(h));					\
	fail_unless(val(k) == ((x) << 1));				\
})


#define clr(x) fail_unless(get(x) == mh_end(h))
#define usd(x) fail_unless(get(x) != mh_end(h))

h = init();
destroy(h);

h = init();
clear(h);

/* access not yet initialized hash */
clr(9);

/* set & test some data. there is first resize here */
set(1);
set(2);
set(3);

tst(1);
tst(2);
tst(3);

/* delete non existing entry; note: index must come from get */
set(4);
k = get(4);
del(k);
del(k);
del(get(4));

set(4);
set(5);
set(6);
set(7);
set(8);
set(9);

/* there is resize after 8 elems. verify they are inplace */
tst(4);
tst(5);
tst(6);
tst(7);
tst(8);
tst(9);

clear(h);

/* after clear no items should exist */
clr(1);
clr(2);
clr(3);
clr(4);
clr(5);
clr(6);
clr(7);
clr(8);
clr(9);
clr(10);
clr(11);

/* set after del */
set(1);
rm(1);
set(1);

destroy(h);
h = init();
set(0);
set(1);
set(2);
set(3);
set(4);
set(5);
set(6);
set(7);

usd(0);
rm(0);
clr(0);
usd(1);
rm(1);
clr(1);
usd(2);
rm(2);
clr(2);
usd(3);
rm(3);
clr(3);
usd(4);
rm(4);
clr(4);
usd(5);
rm(5);
clr(5);
usd(6);
rm(6);
clr(6);
usd(7);
rm(7);
clr(7);

set(8);
set(9);
set(10);
tst(8);
tst(9);
tst(10);

set(1);
set(1);
tst(1);

rm(1);
rm(1);
clr(1);

/* verify overflow of hash index over hash table */
int i;
for (i = 0 ; i < 20; i++) {
	set(i);
}
for (i = 0 ; i < 20; i++) {
	tst(i);
}

destroy(h);

h = init();
set(0);
set(1);
set(2);
set(3);
set(4);
set(5);
set(6);
set(7);
rm(0);
rm(1);
rm(2);
rm(3);
rm(4);

destroy(h);

/* verify reuse of deleted elements */
h = init();
set(1);
int k1 = get(1);
rm(1);
set(1);
int k2 = get(1);
fail_unless(k1 == k2);
destroy(h);

#undef set
#undef rm
#undef tst
#undef clr
#undef usd

#undef init
#undef clear
#undef destroy
#undef get
#undef put
#undef del
#undef key
#undef val