@@ -278,7 +278,7 @@ class PhTreeV16 {
278
278
* whose second element is a bool that is true if the value was actually relocated.
279
279
*/
280
280
template <typename PRED>
281
- size_t relocate_if2 (const KeyT& old_key, const KeyT& new_key, PRED pred) {
281
+ [[deprecated]] size_t relocate_if2 (const KeyT& old_key, const KeyT& new_key, PRED pred) {
282
282
auto pair = _find_two (old_key, new_key);
283
283
auto & iter_old = pair.first ;
284
284
auto & iter_new = pair.second ;
@@ -315,8 +315,6 @@ class PhTreeV16 {
315
315
return 1 ;
316
316
}
317
317
318
- // TODO is this a memory leak problem?????
319
-
320
318
/*
321
319
* Relocate (move) an entry from one position to another, subject to a predicate.
322
320
*
@@ -327,77 +325,6 @@ class PhTreeV16 {
327
325
* @return A pair, whose first element points to the possibly relocated value, and
328
326
* whose second element is a bool that is true if the value was actually relocated.
329
327
*/
330
- // TODO: test work with old relocate_if(). It also work with std::map
331
- // TODO test also FAILS with B-Plus_tree_map; but not with array_map!
332
- // WITHOUT ITERATOR
333
- template <typename PRED>
334
- auto relocate_ifX (const KeyT& old_key, const KeyT& new_key, PRED&& pred) {
335
- bit_width_t n_diverging_bits = NumberOfDivergingBits (old_key, new_key);
336
-
337
- EntryT* current_entry = &root_; // An entry.
338
- EntryT* old_node_entry = nullptr ; // Node that contains entry to be removed
339
- EntryT* old_node_entry_parent = nullptr ; // Parent of the old_node_entry
340
- EntryT* new_node_entry = nullptr ; // Node that will contain new entry
341
- // Find node for removal
342
- while (current_entry && current_entry->IsNode ()) {
343
- old_node_entry_parent = old_node_entry;
344
- old_node_entry = current_entry;
345
- auto postfix_len = old_node_entry->GetNodePostfixLen ();
346
- if (postfix_len + 1 >= n_diverging_bits) {
347
- new_node_entry = old_node_entry;
348
- }
349
- // TODO stop earlier, we are going to have to redo this after insert....
350
- current_entry = current_entry->GetNode ().Find (old_key, postfix_len);
351
- }
352
- EntryT* old_entry = current_entry; // Entry to be removed
353
-
354
- // Can we stop already?
355
- if (old_entry == nullptr || !pred (old_entry->GetValue ())) {
356
- return 0 ; // old_key not found!
357
- }
358
-
359
- // Are the keys equal? Or is the quadrant the same? -> same entry
360
- if (n_diverging_bits == 0 || old_node_entry->GetNodePostfixLen () >= n_diverging_bits) {
361
- old_entry->SetKey (new_key);
362
- return 1 ;
363
- }
364
-
365
- // Find node for insertion
366
- auto new_entry = new_node_entry;
367
- while (new_entry && new_entry->IsNode ()) {
368
- new_node_entry = new_entry;
369
- new_entry = new_entry->GetNode ().Find (new_key, new_entry->GetNodePostfixLen ());
370
- }
371
- if (new_entry != nullptr ) {
372
- return 0 ; // Entry exists!
373
- }
374
- bool is_inserted = false ;
375
- // TODO remove "if"
376
- if (new_entry == nullptr ) { // TODO use in-node pointer
377
- new_entry = &new_node_entry->GetNode ().Emplace (
378
- is_inserted,
379
- new_key,
380
- new_node_entry->GetNodePostfixLen (),
381
- std::move (old_entry->ExtractValue ()));
382
- }
383
-
384
- // Erase old value. See comments in try_emplace(iterator) for details.
385
- if (old_node_entry_parent == new_node_entry) {
386
- // In this case the old_node_entry may have been invalidated by the previous
387
- // insertion.
388
- old_node_entry = old_node_entry_parent;
389
- }
390
-
391
- bool found = false ;
392
- while (old_node_entry) {
393
- old_node_entry = old_node_entry->GetNode ().Erase (
394
- old_key, old_node_entry, old_node_entry != &root_, found);
395
- }
396
- assert (found);
397
- return 1 ;
398
- }
399
-
400
- // WITH ITERATOR
401
328
template <typename PRED>
402
329
auto relocate_if (const KeyT& old_key, const KeyT& new_key, PRED&& pred) {
403
330
bit_width_t n_diverging_bits = NumberOfDivergingBits (old_key, new_key);
@@ -418,7 +345,7 @@ class PhTreeV16 {
418
345
}
419
346
// TODO stop earlier, we are going to have to redo this after insert....
420
347
bool is_found = false ;
421
- iter = current_entry->GetNode ().FindIter (old_key, postfix_len, is_found);
348
+ iter = current_entry->GetNode ().LowerBound (old_key, postfix_len, is_found);
422
349
current_entry = is_found ? &iter->second : nullptr ;
423
350
}
424
351
EntryT* old_entry = current_entry; // Entry to be removed
@@ -439,15 +366,13 @@ class PhTreeV16 {
439
366
bool is_found = false ;
440
367
while (new_entry && new_entry->IsNode ()) {
441
368
new_node_entry = new_entry;
442
- iter = new_entry->GetNode ().FindIter (new_key, new_entry->GetNodePostfixLen (), is_found);
369
+ iter =
370
+ new_entry->GetNode ().LowerBound (new_key, new_entry->GetNodePostfixLen (), is_found);
443
371
new_entry = is_found ? &iter->second : nullptr ;
444
372
}
445
373
if (is_found) {
446
374
return 0 ; // Entry exists
447
375
}
448
- if (new_entry != nullptr ) {
449
- return 0 ; // Entry exists!
450
- }
451
376
bool is_inserted = false ;
452
377
new_entry = &new_node_entry->GetNode ().Emplace (
453
378
iter,
@@ -463,13 +388,13 @@ class PhTreeV16 {
463
388
old_node_entry = old_node_entry_parent;
464
389
}
465
390
466
- bool found = false ;
467
- // TODO use in-node pointer
391
+ is_found = false ;
392
+ // TODO use in-node iterator if possible
468
393
while (old_node_entry) {
469
394
old_node_entry = old_node_entry->GetNode ().Erase (
470
- old_key, old_node_entry, old_node_entry != &root_, found );
395
+ old_key, old_node_entry, old_node_entry != &root_, is_found );
471
396
}
472
- assert (found );
397
+ assert (is_found );
473
398
return 1 ;
474
399
}
475
400
@@ -525,18 +450,6 @@ class PhTreeV16 {
525
450
return std::make_pair (iter1, iter2);
526
451
}
527
452
528
- // TODO what is different/required for MM:
529
- // - "old" is not always removed
530
- // - "new" may exist, but may not result in collision
531
- // TODO i.e. we need three conditions:
532
- // - pred_move ( {return is_valid(old); } )
533
- // - pred_can_be_moved ( { return destination.emplace() == true; } )
534
- // - pred_remove_old ( { source.erase(); return source.empty(); } )
535
-
536
- // TODO
537
- // - relocate(key, key, value) relocates 0 or 1 entries...?
538
- // - relocate_if(key, key) relocates potentially many keys
539
-
540
453
public:
541
454
/*
542
455
* Tries to locate two entries that are 'close' to each other.
@@ -555,7 +468,7 @@ class PhTreeV16 {
555
468
bit_width_t n_diverging_bits = NumberOfDivergingBits (old_key, new_key);
556
469
557
470
if (!verify_exists && n_diverging_bits == 0 ) {
558
- return 1 ; // TODO COUNT()?
471
+ return 1 ; // We omit calling because that would require looking up the entry...
559
472
}
560
473
561
474
EntryT* new_entry = &root_; // An entry.
@@ -682,7 +595,6 @@ class PhTreeV16 {
682
595
return std::make_pair (iter1, iter2);
683
596
}
684
597
685
- public:
686
598
/*
687
599
* Iterates over all entries in the tree. The optional filter allows filtering entries and nodes
688
600
* (=sub-trees) before returning / traversing them. By default, all entries are returned. Filter
@@ -862,26 +774,6 @@ class PhTreeV16 {
862
774
return {parent, entry_iter};
863
775
}
864
776
865
- std::pair<EntryT*, EntryIteratorC<DIM, EntryT>> find_starting_node (
866
- const KeyT& key1, const KeyT& key2, bit_width_t & max_conflicting_bits) {
867
- auto & prefix = key1;
868
- max_conflicting_bits = NumberOfDivergingBits (key1, key2);
869
- EntryT* parent = &root_;
870
- if (max_conflicting_bits > root_.GetNodePostfixLen ()) {
871
- // Abort early if we have no shared prefix in the query
872
- return {&root_, root_.GetNode ().Entries ().end ()};
873
- }
874
- EntryIterator<DIM, EntryT> entry_iter =
875
- root_.GetNode ().FindPrefix (prefix, max_conflicting_bits, root_.GetNodePostfixLen ());
876
- while (entry_iter != parent->GetNode ().Entries ().end () && entry_iter->second .IsNode () &&
877
- entry_iter->second .GetNodePostfixLen () >= max_conflicting_bits) {
878
- parent = &entry_iter->second ;
879
- entry_iter = parent->GetNode ().FindPrefix (
880
- prefix, max_conflicting_bits, parent->GetNodePostfixLen ());
881
- }
882
- return {parent, entry_iter};
883
- }
884
-
885
777
size_t num_entries_;
886
778
// Contract: root_ contains a Node with 0 or more entries. The root node is the only Node
887
779
// that is allowed to have less than two entries.
0 commit comments