Skip to content

Commit e0ed908

Browse files
committed
Add updating parent max after insert (fix error in rare cases)
1 parent e18accd commit e0ed908

File tree

2 files changed

+1
-4
lines changed

2 files changed

+1
-4
lines changed

src/IntervalTree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function insert(Interval $interval, $value = null): Node
9494
$insertNode->setColor(NodeColor::red());
9595

9696
$this->treeInsert($insertNode);
97+
$insertNode->updateMax();
9798
$this->recalculateMax($insertNode);
9899
return $insertNode;
99100
}
@@ -208,7 +209,6 @@ private function insertFixup(Node $insertNode): void
208209
}
209210
}
210211
}
211-
212212
$this->root->setColor(NodeColor::black());
213213
}
214214

src/Node.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ public function updateMax(): void
132132
if ($this->getLeft()->max !== null) {
133133
$this->max = $this->max->merge($this->getLeft()->max);
134134
}
135-
if ($this->getParent() !== null) {
136-
$this->getParent()->updateMax();
137-
}
138135
}
139136

140137
public function notIntersectLeftSubtree(Node $searchNode): bool

0 commit comments

Comments
 (0)