Skip to content

Commit

Permalink
perf: improve speed of TreeSet.first/last
Browse files Browse the repository at this point in the history
  • Loading branch information
rbellens committed Feb 26, 2024
1 parent 1ab8a57 commit 8273472
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/src/treeset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,21 @@ class AvlNode<V> {
int get balanceFactor => (right?.height ?? 0) - (left?.height ?? 0);

AvlNode<V> get minimumNode {
if (left == null) return this;
return left!.minimumNode;
var x = this;

while (x.left != null) {
x = x.left!;
}
return x;
}

AvlNode<V> get maximumNode {
if (right == null) return this;
return right!.maximumNode;
var x = this;

while (x.right != null) {
x = x.right!;
}
return x;
}

AvlNode<V> add(Comparator<V> comparator, V element) {
Expand Down

0 comments on commit 8273472

Please sign in to comment.