| 1002 | } |
| 1003 | |
| 1004 | const 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 | |
| 1031 | const visitBetween = <K, V, A>( |
| 1032 | node: Node.Node<K, V>, |