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