@@ -76,7 +76,7 @@ void sharing_map_internals_test()
76
76
77
77
sm.insert (" i" , " 1" );
78
78
count = sm.count_unmarked_nodes (false , marked, false );
79
- REQUIRE (count == 3 );
79
+ REQUIRE (count == 2 );
80
80
REQUIRE (marked.empty ());
81
81
82
82
count = sm.count_unmarked_nodes (true , marked, false );
@@ -119,7 +119,8 @@ void sharing_map_internals_test()
119
119
{
120
120
std::set<const void *> marked;
121
121
std::size_t count = 0 ;
122
- std::size_t chunk = 3 ;
122
+ const std::size_t chunk = sharing_map_unsignedt::chunk;
123
+ const std::size_t levels = sharing_map_unsignedt::levels;
123
124
124
125
sharing_map_unsignedt sm;
125
126
@@ -128,58 +129,94 @@ void sharing_map_internals_test()
128
129
129
130
sm.insert (0 , " a" );
130
131
count = sm.count_unmarked_nodes (false , marked, false );
131
- REQUIRE (count == 3 );
132
+ REQUIRE (count == 2 );
132
133
133
134
SECTION (" first node decisive" )
134
135
{
135
136
sm.insert (1 , " b" );
136
137
count = sm.count_unmarked_nodes (false , marked, false );
137
- REQUIRE (count == 5 );
138
+ REQUIRE (count == 3 );
138
139
139
140
sm.replace (1 , " c" );
140
141
count = sm.count_unmarked_nodes (false , marked, false );
141
- REQUIRE (count == 5 );
142
+ REQUIRE (count == 3 );
142
143
143
144
sm.erase (1 );
144
145
count = sm.count_unmarked_nodes (false , marked, false );
145
- REQUIRE (count == 3 );
146
+ REQUIRE (count == 2 );
146
147
}
147
148
148
149
SECTION (" second node decisive" )
149
150
{
150
151
sm.insert (1 << chunk, " b" );
151
152
count = sm.count_unmarked_nodes (false , marked, false );
152
- REQUIRE (count == 6 );
153
+ REQUIRE (count == 4 );
153
154
154
155
sm.replace (1 << chunk, " c" );
155
156
count = sm.count_unmarked_nodes (false , marked, false );
156
- REQUIRE (count == 6 );
157
+ REQUIRE (count == 4 );
157
158
158
159
sm.erase (1 << chunk);
159
160
count = sm.count_unmarked_nodes (false , marked, false );
160
- REQUIRE (count == 4 );
161
+ REQUIRE (count == 3 );
161
162
}
162
163
163
164
SECTION (" third node decisive" )
164
165
{
165
166
sm.insert (1 << (2 * chunk), " b" );
166
167
count = sm.count_unmarked_nodes (false , marked, false );
167
- REQUIRE (count == 7 );
168
+ REQUIRE (count == 5 );
168
169
169
170
sm.replace (1 << (2 * chunk), " c" );
170
171
count = sm.count_unmarked_nodes (false , marked, false );
171
- REQUIRE (count == 7 );
172
+ REQUIRE (count == 5 );
172
173
173
174
sm.erase (1 << (2 * chunk));
174
175
count = sm.count_unmarked_nodes (false , marked, false );
175
- REQUIRE (count == 5 );
176
+ REQUIRE (count == 4 );
177
+ }
178
+
179
+ SECTION (" last non-container node is decisive" )
180
+ {
181
+ sm.insert (1 << (chunk * (levels - 1 )), " b" );
182
+ count = sm.count_unmarked_nodes (false , marked, false );
183
+ REQUIRE (count == levels + 2 ); // inner nodes + leafs
184
+
185
+ sm.replace (1 << (chunk * (levels - 1 )), " c" );
186
+ count = sm.count_unmarked_nodes (false , marked, false );
187
+ REQUIRE (count == levels + 2 ); // inner nodes + leafs
188
+
189
+ sm.erase (1 << (chunk * (levels - 1 )));
190
+ count = sm.count_unmarked_nodes (false , marked, false );
191
+ REQUIRE (count == levels + 1 ); // inner nodes + leafs
192
+ }
193
+
194
+ SECTION (" stored in container node" )
195
+ {
196
+ // existing leaf will be migrated to the bottom
197
+ sm.insert (1 << (chunk * levels), " b" );
198
+ count = sm.count_unmarked_nodes (false , marked, false );
199
+ REQUIRE (count == levels + 1 + 2 ); // inner nodes + container + leafs
200
+
201
+ sm.replace (1 << (chunk * levels), " c" );
202
+ count = sm.count_unmarked_nodes (false , marked, false );
203
+ REQUIRE (count == levels + 1 + 2 ); // inner nodes + container + leafs
204
+
205
+ sm.erase (1 << (chunk * levels));
206
+ count = sm.count_unmarked_nodes (false , marked, false );
207
+ REQUIRE (count == levels + 1 + 1 ); // inner nodes + container + leafs
208
+
209
+ // existing leaf still in container, not migrating necessary
210
+ sm.insert (1 << (chunk * levels), " d" );
211
+ count = sm.count_unmarked_nodes (false , marked, false );
212
+ REQUIRE (count == levels + 1 + 2 ); // inner nodes + container + leafs
176
213
}
177
214
}
178
215
179
216
SECTION (" delta view (sharing, one of the maps is deeper)" )
180
217
{
181
218
std::set<const void *> marked;
182
- std::size_t chunk = 3 ;
219
+ std::size_t chunk = sharing_map_unsignedt::chunk ;
183
220
184
221
std::vector<sharing_map_unsignedt> v;
185
222
v.reserve (2 );
@@ -200,10 +237,10 @@ void sharing_map_internals_test()
200
237
sharing_map_unsignedt::sharing_map_statst sms;
201
238
202
239
sms = sharing_map_unsignedt::get_sharing_stats (v.begin (), v.end ());
203
- REQUIRE (sms.num_leafs == 3 );
204
- REQUIRE (sms.num_unique_leafs == 2 );
205
- REQUIRE (sms.num_nodes == 3 + 7 );
206
- REQUIRE (sms.num_unique_nodes == 3 + 5 );
240
+ REQUIRE (sms.num_leafs == 1 + 2 );
241
+ REQUIRE (sms.num_unique_leafs == 1 + 1 );
242
+ REQUIRE (sms.num_nodes == 2 + 5 );
243
+ REQUIRE (sms.num_unique_nodes == 2 + 4 );
207
244
#endif
208
245
209
246
sharing_map_unsignedt::delta_viewt delta_view;
0 commit comments