MCPcopy
hub / github.com/Effect-TS/effect / at

Function at

packages/effect/src/internal/redBlackTree.ts:132–169  ·  view source on GitHub ↗
(
  self: RBT.RedBlackTree<K, V>,
  index: number,
  direction: RBT.RedBlackTree.Direction
)

Source from the content-addressed store, hash-verified

130>(2, (self, index) => at(self, index, Direction.Forward))
131
132const at = <K, V>(
133 self: RBT.RedBlackTree<K, V>,
134 index: number,
135 direction: RBT.RedBlackTree.Direction
136): Iterable<[K, V]> => {
137 return {
138 [Symbol.iterator]: () => {
139 if (index < 0) {
140 return new RedBlackTreeIterator(self, [], direction)
141 }
142 let node = (self as RedBlackTreeImpl<K, V>)._root
143 const stack: Array<Node.Node<K, V>> = []
144 while (node !== undefined) {
145 stack.push(node)
146 if (node.left !== undefined) {
147 if (index < node.left.count) {
148 node = node.left
149 continue
150 }
151 index -= node.left.count
152 }
153 if (!index) {
154 return new RedBlackTreeIterator(self, stack, direction)
155 }
156 index -= 1
157 if (node.right !== undefined) {
158 if (index >= node.right.count) {
159 break
160 }
161 node = node.right
162 } else {
163 break
164 }
165 }
166 return new RedBlackTreeIterator(self, [], direction)
167 }
168 }
169}
170
171/** @internal */
172export const findAll = dual<

Callers 1

redBlackTree.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected