@@ -200,6 +200,48 @@ START_TEST(test_art_insert_delete)
200
200
}
201
201
END_TEST
202
202
203
+ START_TEST (test_art_insert_random_delete )
204
+ {
205
+ art_tree t ;
206
+ int res = art_tree_init (& t );
207
+ fail_unless (res == 0 );
208
+
209
+ int len ;
210
+ char buf [512 ];
211
+ FILE * f = fopen ("tests/words.txt" , "r" );
212
+
213
+ uintptr_t line = 1 ;
214
+ while (fgets (buf , sizeof buf , f )) {
215
+ len = strlen (buf );
216
+ buf [len - 1 ] = '\0' ;
217
+ fail_unless (NULL ==
218
+ art_insert (& t , (unsigned char * )buf , len , (void * )line ));
219
+ line ++ ;
220
+ }
221
+
222
+ // Can be improved ensuring one delete on each node type
223
+ // A is in 48 node
224
+ uintptr_t lineno = 1 ;
225
+ // Search first, ensure all entries are visible
226
+ uintptr_t val = (uintptr_t )art_search (& t , (unsigned char * )"A" , strlen ("A" )+ 1 );
227
+ fail_unless (lineno == val , "Line: %d Val: %" PRIuPTR " Str: %s\n" , lineno ,
228
+ val , "A" );
229
+
230
+ // Delete a single entry, should get lineno back
231
+ val = (uintptr_t )art_delete (& t , (unsigned char * ) "A" , strlen ("A" )+ 1 );
232
+ fail_unless (lineno == val , "Line: %d Val: %" PRIuPTR " Str: %s\n" , lineno ,
233
+ val , "A" );
234
+
235
+ // Ensure the entry is no longer visible
236
+ val = (uintptr_t )art_search (& t , (unsigned char * )"A" , strlen ("A" )+ 1 );
237
+ fail_unless (0 == val , "Line: %d Val: %" PRIuPTR " Str: %s\n" , 0 ,
238
+ val , "A" );
239
+
240
+ res = art_tree_destroy (& t );
241
+ fail_unless (res == 0 );
242
+ }
243
+ END_TEST
244
+
203
245
int iter_cb (void * data , const unsigned char * key , uint32_t key_len , void * val ) {
204
246
uint64_t * out = (uint64_t * )data ;
205
247
uintptr_t line = (uintptr_t )val ;
@@ -448,5 +490,3 @@ START_TEST(test_art_max_prefix_len_scan_prefix)
448
490
fail_unless (res == 0 );
449
491
}
450
492
END_TEST
451
-
452
-
0 commit comments