(
Node: typeof BinarySearchNode,
value: T,
)
| 358 | } |
| 359 | |
| 360 | #insertNode( |
| 361 | Node: typeof BinarySearchNode, |
| 362 | value: T, |
| 363 | ): BinarySearchNode<T> | null { |
| 364 | if (!this.#root) { |
| 365 | this.#root = new Node(null, value); |
| 366 | this.#size++; |
| 367 | return this.#root; |
| 368 | } else { |
| 369 | let node: BinarySearchNode<T> = this.#root; |
| 370 | while (true) { |
| 371 | const order: number = this.#compare(value, node.value); |
| 372 | if (order === 0) break; |
| 373 | const direction: Direction = order < 0 ? "left" : "right"; |
| 374 | if (node[direction]) { |
| 375 | node = node[direction]!; |
| 376 | } else { |
| 377 | node[direction] = new Node(node, value); |
| 378 | this.#size++; |
| 379 | return node[direction]; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | return null; |
| 384 | } |
| 385 | |
| 386 | /** Removes the given node, and returns the node that was physically removed from the tree. */ |
| 387 | #removeNode( |
no outgoing calls
no test coverage detected