Skip to main content Link Search Menu Expand Document (external link)

RedBlackTree overview

Added in v2.0.0


Table of contents


constants

Direction

Signature

export declare const Direction: { readonly Forward: RedBlackTree.Direction; readonly Backward: RedBlackTree.Direction }

Added in v2.0.0

constructors

empty

Creates an empty RedBlackTree.

Signature

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

Added in v2.0.0

fromIterable

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

Signature

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

Added in v2.0.0

make

Constructs a new RedBlackTree from the specified entries.

Signature

export 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>

Added in v2.0.0

elements

findAll

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

Signature

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

Added in v2.0.0

findFirst

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

Signature

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

Added in v2.0.0

getAt

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

Signature

export 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]>
}

Added in v2.0.0

has

Finds the item with key, if it exists.

Signature

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

Added in v2.0.0

folding

reduce

Reduce a state over the entries of the tree.

Signature

export 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
}

Added in v2.0.0

getters

first

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

Signature

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

Added in v2.0.0

getOrder

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

Signature

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

Added in v2.0.0

keys

Get all the keys present in the tree in order.

Signature

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

Added in v2.0.0

keysReversed

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

Signature

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

Added in v2.0.0

last

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

Signature

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

Added in v2.0.0

size

Returns the size of the tree.

Signature

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

Added in v2.0.0

values

Get all values present in the tree in order.

Signature

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

Added in v2.0.0

valuesReversed

Get all values present in the tree in reverse order.

Signature

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

Added in v2.0.0

models

RedBlackTree (interface)

A Red-Black Tree.

Signature

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

Added in v2.0.0

refinements

isRedBlackTree

Signature

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

Added in v2.0.0

symbol

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v2.0.0

traversing

at

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

export 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]>
}

Added in v2.0.0

atReversed

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

export 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]>
}

Added in v2.0.0

forEach

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

Signature

export 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
}

Added in v2.0.0

forEachBetween

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

Signature

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

Added in v2.0.0

forEachGreaterThanEqual

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

Signature

export 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
}

Added in v2.0.0

forEachLessThan

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

Signature

export 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
}

Added in v2.0.0

greaterThan

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

Signature

export 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]>
}

Added in v2.0.0

greaterThanEqual

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

Signature

export 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]>
}

Added in v2.0.0

greaterThanEqualReversed

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

Signature

export 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]>
}

Added in v2.0.0

greaterThanReversed

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

Signature

export 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]>
}

Added in v2.0.0

lessThan

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

Signature

export 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]>
}

Added in v2.0.0

lessThanEqual

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

Signature

export 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]>
}

Added in v2.0.0

lessThanEqualReversed

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

Signature

export 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]>
}

Added in v2.0.0

lessThanReversed

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

Signature

export 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]>
}

Added in v2.0.0

reversed

Traverse the tree in reverse order.

Signature

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

Added in v2.0.0

utils

RedBlackTree (namespace)

Added in v2.0.0

Direction (type alias)

Signature

export type Direction = number & {
  readonly Direction: unique symbol
}

Added in v2.0.0

insert

Insert a new item into the tree.

Signature

export 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>
}

Added in v2.0.0

removeFirst

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

Signature

export 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>
}

Added in v2.0.0