Skip to content

RedBlackTree

38 exports Added in v2.0.0 Source

Constants

Direction

Added in v2.0.0 Source

Signature

declare const Direction: {
  readonly Backward: Direction;
  readonly Forward: Direction;
};

Constructors

empty

Added in v2.0.0 Source

Creates an empty RedBlackTree.

Signature

declare const empty: <K, V = never>(ord: Order<K>) => RedBlackTree<K, V>;

fromIterable

Added in v2.0.0 Source

Creates a new RedBlackTree from an iterable collection of key/value pairs.

Signature

declare const fromIterable: {
  <B>(ord: Order<B>): <K, V>(entries: Iterable<readonly [K, V]>) => RedBlackTree<K, V>;
  <K, V, B>(entries: Iterable<readonly [K, V]>, ord: Order<B>): RedBlackTree<K, V>;
};

make

Added in v2.0.0 Source

Constructs a new RedBlackTree from the specified entries.

Signature

declare const make: <K>(
  ord: Order<K>,
) => <Entries extends Array<readonly [K, any]>>(
  ...entries: Entries
) => RedBlackTree<K, Entries[number] extends readonly [any, infer V] ? V : never>;

Elements

findAll

Added in v2.0.0 Source

Finds all values in the tree associated with the specified key.

Signature

declare const findAll: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Chunk<V>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Chunk<V>;
};

findFirst

Added in v2.0.0 Source

Finds the first value in the tree associated with the specified key, if it exists.

Signature

declare const findFirst: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Option<V>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Option<V>;
};

getAt

Added in v2.0.0 Source

Returns the element at the specified index within the tree or None if the specified index does not exist.

Signature

declare const getAt: {
  (index: number): <K, V>(self: RedBlackTree<K, V>) => Option<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, index: number): Option<[K, V]>;
};

has

Added in v2.0.0 Source

Finds the item with key, if it exists.

Signature

declare const has: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => boolean;
  <K, V>(self: RedBlackTree<K, V>, key: K): boolean;
};

Folding

reduce

Added in v2.0.0 Source

Reduce a state over the entries of the tree.

Signature

declare const reduce: {
  <Z, V, K>(zero: Z, f: (accumulator: Z, value: V, key: K) => Z): (self: RedBlackTree<K, V>) => Z;
  <Z, V, K>(self: RedBlackTree<K, V>, zero: Z, f: (accumulator: Z, value: V, key: K) => Z): Z;
};

Getters

first

Added in v2.0.0 Source

Returns the first entry in the tree, if it exists.

Signature

declare const first: <K, V>(self: RedBlackTree<K, V>) => Option<[K, V]>;

getOrder

Added in v2.0.0 Source

Gets the Order<K> that the RedBlackTree<K, V> is using.

Signature

declare const getOrder: <K, V>(self: RedBlackTree<K, V>) => Order<K>;

keys

Added in v2.0.0 Source

Get all the keys present in the tree in order.

Signature

declare const keys: <K, V>(self: RedBlackTree<K, V>) => IterableIterator<K>;

keysReversed

Added in v2.0.0 Source

Get all the keys present in the tree in reverse order.

Signature

declare const keysReversed: <K, V>(self: RedBlackTree<K, V>) => IterableIterator<K>;

last

Added in v2.0.0 Source

Returns the last entry in the tree, if it exists.

Signature

declare const last: <K, V>(self: RedBlackTree<K, V>) => Option<[K, V]>;

size

Added in v2.0.0 Source

Returns the size of the tree.

Signature

declare const size: <K, V>(self: RedBlackTree<K, V>) => number;

values

Added in v2.0.0 Source

Get all values present in the tree in order.

Signature

declare const values: <K, V>(self: RedBlackTree<K, V>) => IterableIterator<V>;

Get all values present in the tree in reverse order.

Signature

declare const valuesReversed: <K, V>(self: RedBlackTree<K, V>) => IterableIterator<V>;

Models

RedBlackTree interface

Added in v2.0.0 Source

A Red-Black Tree.

Signature

interface RedBlackTree<in out Key, out Value>
  extends Iterable<[Key, Value]>, Equal, Pipeable, Inspectable {
  readonly [TypeId]: {
    readonly _Key: Invariant<Key>;
    readonly _Value: Covariant<Value>;
  };
}

Other

insert

Added in v2.0.0 Source

Insert a new item into the tree.

Signature

declare const insert: {
  <K, V>(key: K, value: V): (self: RedBlackTree<K, V>) => RedBlackTree<K, V>;
  <K, V>(self: RedBlackTree<K, V>, key: K, value: V): RedBlackTree<K, V>;
};

RedBlackTree

Added in v2.0.0 Source

removeFirst

Added in v2.0.0 Source

Removes the entry with the specified key, if it exists.

Signature

declare const removeFirst: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => RedBlackTree<K, V>;
  <K, V>(self: RedBlackTree<K, V>, key: K): RedBlackTree<K, V>;
};

Refinements

Signature

declare const isRedBlackTree: {
  <K, V>(u: Iterable<readonly [K, V]>): u is RedBlackTree<K, V>;
  (u: unknown): u is RedBlackTree<unknown, unknown>;
};

Symbol

TypeId type

Added in v2.0.0 Source

Signature

type TypeId = typeof TypeId;

Traversing

at

Added in v2.0.0 Source

Returns an iterator that points to the element at the specified index of the tree.

Note: The iterator will run through elements in order.

Signature

declare const at: {
  (index: number): <K, V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, index: number): Iterable<[K, V]>;
};

atReversed

Added in v2.0.0 Source

Returns an iterator that points to the element at the specified index of the tree.

Note: The iterator will run through elements in reverse order.

Signature

declare const atReversed: {
  (index: number): <K, V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, index: number): Iterable<[K, V]>;
};

forEach

Added in v2.0.0 Source

Execute the specified function for each node of the tree, in order.

Signature

declare const forEach: {
  <K, V>(f: (key: K, value: V) => void): (self: RedBlackTree<K, V>) => void;
  <K, V>(self: RedBlackTree<K, V>, f: (key: K, value: V) => void): void;
};

Visit each node of the tree in order with key lower than max and greater than or equal to min.

Signature

declare const forEachBetween: {
  <K, V>(options: {
    readonly body: (key: K, value: V) => void;
    readonly max: K;
    readonly min: K;
  }): (self: RedBlackTree<K, V>) => void;
  <K, V>(
    self: RedBlackTree<K, V>,
    options: {
      readonly body: (key: K, value: V) => void;
      readonly max: K;
      readonly min: K;
    },
  ): void;
};

Visit each node of the tree in order with key greater then or equal to max.

Signature

declare const forEachGreaterThanEqual: {
  <K, V>(min: K, f: (key: K, value: V) => void): (self: RedBlackTree<K, V>) => void;
  <K, V>(self: RedBlackTree<K, V>, min: K, f: (key: K, value: V) => void): void;
};

Visit each node of the tree in order with key lower then max.

Signature

declare const forEachLessThan: {
  <K, V>(max: K, f: (key: K, value: V) => void): (self: RedBlackTree<K, V>) => void;
  <K, V>(self: RedBlackTree<K, V>, max: K, f: (key: K, value: V) => void): void;
};

greaterThan

Added in v2.0.0 Source

Returns an iterator that traverse entries in order with keys greater than the specified key.

Signature

declare const greaterThan: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

Returns an iterator that traverse entries in order with keys greater than or equal to the specified key.

Signature

declare const greaterThanEqual: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

Returns an iterator that traverse entries in reverse order with keys greater than or equal to the specified key.

Signature

declare const greaterThanEqualReversed: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

Returns an iterator that traverse entries in reverse order with keys greater than the specified key.

Signature

declare const greaterThanReversed: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

lessThan

Added in v2.0.0 Source

Returns an iterator that traverse entries in order with keys less than the specified key.

Signature

declare const lessThan: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

Returns an iterator that traverse entries in order with keys less than or equal to the specified key.

Signature

declare const lessThanEqual: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

Returns an iterator that traverse entries in reverse order with keys less than or equal to the specified key.

Signature

declare const lessThanEqualReversed: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

Returns an iterator that traverse entries in reverse order with keys less than the specified key.

Signature

declare const lessThanReversed: {
  <K>(key: K): <V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;
  <K, V>(self: RedBlackTree<K, V>, key: K): Iterable<[K, V]>;
};

reversed

Added in v2.0.0 Source

Traverse the tree in reverse order.

Signature

declare const reversed: <K, V>(self: RedBlackTree<K, V>) => Iterable<[K, V]>;