From b75648ee7488d1c7a05f92a4c4e4212e2da10269 Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Tue, 24 Sep 2024 15:34:06 +0200 Subject: [PATCH] SortedSetExt: added FindValue and FindNeighboursV --- .../AlgoDat/ExtendedCore/SortedSetExt.cs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Aardvark.Base/AlgoDat/ExtendedCore/SortedSetExt.cs b/src/Aardvark.Base/AlgoDat/ExtendedCore/SortedSetExt.cs index 94584d09..b8079d82 100644 --- a/src/Aardvark.Base/AlgoDat/ExtendedCore/SortedSetExt.cs +++ b/src/Aardvark.Base/AlgoDat/ExtendedCore/SortedSetExt.cs @@ -914,7 +914,7 @@ internal virtual Node FindNode(T item) } - internal virtual Tuple FindNeighbours(T item) + internal virtual (Node, Node, Node) FindNeighbours(T item) { Node current = _root; Node left = null; @@ -958,7 +958,7 @@ internal virtual Tuple FindNeighbours(T item) } } - return Tuple.Create(left, self, right); + return (left, self, right); } @@ -1958,7 +1958,6 @@ public virtual SortedSetExt GetViewBetween(T lowerValue, T upperValue) return new TreeSubSet(this, lowerValue, upperValue, true, true); } - public bool TryFindGreater(T lowerValue, out T result) { var tup = FindNeighbours(lowerValue); @@ -2003,6 +2002,32 @@ public void FindNeighbours(T value, out Optional lower, out Optional self, else upper = Optional.None; } + /// + /// Find the neighbours of the given value + /// returns (hasLower, hasValue, hasUpper) and the corresponding values in the out p + /// + public (bool, bool, bool) FindNeighboursV(T value, out T lower, out T self, out T upper) + { + var (l, s, u) = FindNeighbours(value); + + lower = l != null ? l.Item : default; + self = s != null ? s.Item : default; + upper = u != null ? u.Item : default; + + return (l != null, s != null, u != null); + } + + + /// + /// Checks if the value is present in the set and returns the value (might be different to the value passed in when using custom IComparer) + /// + public bool FindValue(T value, out T result) + { + var val = FindNode(value); + result = val != null ? val.Item : default; + return val != null; + } + #if DEBUG