MCPcopy Index your code
hub / github.com/Effect-TS/effect / visitLessThan

Function visitLessThan

packages/effect/src/internal/redBlackTree.ts:1004–1029  ·  view source on GitHub ↗
(
  node: Node.Node<K, V>,
  max: K,
  ord: Order.Order<K>,
  visit: (key: K, value: V) => Option.Option<A>
)

Source from the content-addressed store, hash-verified

1002}
1003
1004const visitLessThan = <K, V, A>(
1005 node: Node.Node<K, V>,
1006 max: K,
1007 ord: Order.Order<K>,
1008 visit: (key: K, value: V) => Option.Option<A>
1009): Option.Option<A> => {
1010 let current: Node.Node<K, V> | undefined = node
1011 let stack: Stack.Stack<Node.Node<K, V>> | undefined = undefined
1012 let done = false
1013 while (!done) {
1014 if (current !== undefined) {
1015 stack = Stack.make(current, stack)
1016 current = current.left
1017 } else if (stack !== undefined && ord(max, stack.value.key) > 0) {
1018 const value = visit(stack.value.key, stack.value.value)
1019 if (Option.isSome(value)) {
1020 return value
1021 }
1022 current = stack.value.right
1023 stack = stack.previous
1024 } else {
1025 done = true
1026 }
1027 }
1028 return Option.none()
1029}
1030
1031const visitBetween = <K, V, A>(
1032 node: Node.Node<K, V>,

Callers 1

redBlackTree.tsFile · 0.85

Calls 1

makeMethod · 0.65

Tested by

no test coverage detected