Skip to content

Commit

Permalink
SortedSetExt: added FindValue and FindNeighboursV
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 24, 2024
1 parent 85d2519 commit b75648e
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Aardvark.Base/AlgoDat/ExtendedCore/SortedSetExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ internal virtual Node FindNode(T item)
}


internal virtual Tuple<Node, Node, Node> FindNeighbours(T item)
internal virtual (Node, Node, Node) FindNeighbours(T item)
{
Node current = _root;
Node left = null;
Expand Down Expand Up @@ -958,7 +958,7 @@ internal virtual Tuple<Node, Node, Node> FindNeighbours(T item)
}
}

return Tuple.Create(left, self, right);
return (left, self, right);
}


Expand Down Expand Up @@ -1958,7 +1958,6 @@ public virtual SortedSetExt<T> 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);
Expand Down Expand Up @@ -2003,6 +2002,32 @@ public void FindNeighbours(T value, out Optional<T> lower, out Optional<T> self,
else upper = Optional<T>.None;
}

/// <summary>
/// Find the neighbours of the given value
/// returns (hasLower, hasValue, hasUpper) and the corresponding values in the out p
/// </summary>
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);
}


/// <summary>
/// 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)
/// </summary>
public bool FindValue(T value, out T result)
{
var val = FindNode(value);
result = val != null ? val.Item : default;
return val != null;
}


#if DEBUG

Expand Down

0 comments on commit b75648e

Please sign in to comment.