All files / data_structures / _red_black_node.ts

100.00% Branches 0/0
100.00% Lines 15/15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
 
 
x80
 
 
x80
 
 
 
x80
 
x80
x1565
x1565
x1565
 
x80
x105
x105
x105
x105
x105
x105
x80























// Copyright 2018-2025 the Deno authors. MIT license.
// This module is browser compatible.

import { BinarySearchNode, type Direction } from "./_binary_search_node.ts";
export type { Direction };

export class RedBlackNode<T> extends BinarySearchNode<T> {
  declare parent: RedBlackNode<T> | null;
  declare left: RedBlackNode<T> | null;
  declare right: RedBlackNode<T> | null;
  red: boolean;

  constructor(parent: RedBlackNode<T> | null, value: T) {
    super(parent, value);
    this.red = true;
  }

  static override from<T>(node: RedBlackNode<T>): RedBlackNode<T> {
    const copy: RedBlackNode<T> = new RedBlackNode(node.parent, node.value);
    copy.left = node.left;
    copy.right = node.right;
    copy.red = node.red;
    return copy;
  }
}