BkTree: Bugfix node deletion.

I think it's working now!
This commit is contained in:
Starbeamrainbowlabs 2020-03-09 21:32:06 +00:00
parent 296139049a
commit 6480d72323
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 3 additions and 3 deletions

View File

@ -167,7 +167,7 @@ class BkTree
$parent = $stack[count($stack) - 2]; $parent = $stack[count($stack) - 2];
// 1. Delete the connection from parent -> target // 1. Delete the connection from parent -> target
foreach($parent["node"]->children as $distance -> $id) { foreach($parent["node"]->children as $distance => $id) {
if($id == $node_target_id) { if($id == $node_target_id) {
unset($parent["node"]->children->$distance); unset($parent["node"]->children->$distance);
break; break;
@ -182,7 +182,7 @@ class BkTree
// NOTE: We need to be careful that the characteristics of the tree are preserved. We should test this by tracing a node's location in the tree and purposefully removing nodes in the chain and see if the results returned as still the same // NOTE: We need to be careful that the characteristics of the tree are preserved. We should test this by tracing a node's location in the tree and purposefully removing nodes in the chain and see if the results returned as still the same
// //
// Hang the now orphaned children and all their decendants from the parent // Hang the now orphaned children and all their decendants from the parent
foreach($node_target->children as $distance -> $id) { foreach($node_target->children as $distance => $id) {
$orphan = $this->box->get("node|$id"); $orphan = $this->box->get("node|$id");
$substack = [ [ "node" => $orphan, "id" => $id ] ]; $substack_top = 0; $substack = [ [ "node" => $orphan, "id" => $id ] ]; $substack_top = 0;
while($substack_top >= 0) { while($substack_top >= 0) {
@ -191,7 +191,7 @@ class BkTree
$substack_top--; $substack_top--;
$this->box->delete("node|{$next["id"]}"); // Delete the orphan node $this->box->delete("node|{$next["id"]}"); // Delete the orphan node
$this->add($next["node"], $parent["id"]); // Re-hang it from the parent $this->add($next["node"]->value, $parent["id"]); // Re-hang it from the parent
foreach($next["node"]->children as $distance => $sub_id) { foreach($next["node"]->children as $distance => $sub_id) {
$substack[++$substack_top] = [ $substack[++$substack_top] = [