Options
All
  • Public
  • Public/Protected
  • All
Menu

The class implementation of the public API interface IAVLTree.

Type parameters

  • K: Ord

    The key type that is derived from tree values, in order to compare their order.

  • V

    The type of values that are to be stored in the tree.

Hierarchy

  • AVLTree

Implements

Index

Constructors

constructor

Properties

Private root

root: null | AVLNode<K, V> = null

Methods

delete

  • delete(key: K): boolean
  • Deletes the node with given key from the tree.

    Parameters

    • key: K

    Returns boolean

    A boolean that indicates whether a node was deleted: false if the given key was not found in the tree, or true otherwise.

foldLeft

  • foldLeft<T>(fn: (acc: T, value: V) => T, seed: T): T
  • Folds (reduces) the tree left-to-right using in-order traversal.

    Type parameters

    • T

    Parameters

    • fn: (acc: T, value: V) => T
        • (acc: T, value: V): T
        • Parameters

          • acc: T
          • value: V

          Returns T

    • seed: T

    Returns T

    The accumulation of the tree.

foldRight

  • foldRight<T>(fn: (acc: T, value: V) => T, seed: T): T
  • Folds (reduces) the tree right-to-left using reversed in-order traversal.

    Type parameters

    • T

    Parameters

    • fn: (acc: T, value: V) => T
        • (acc: T, value: V): T
        • Parameters

          • acc: T
          • value: V

          Returns T

    • seed: T

    Returns T

    The accumulation value.

forEach

  • forEach(fn: (element: V) => void): void
  • Performs in-order traversal of the tree, applying the given fn to each contained value.

    Parameters

    • fn: (element: V) => void
        • (element: V): void
        • Parameters

          • element: V

          Returns void

    Returns void

insert

  • insert(value: V): boolean
  • Inserts a new value into the tree.

    Parameters

    • value: V

    Returns boolean

    A boolean that indicates whether a node was inserted: false if the key derived from given value is already in the tree, or true otherwise.

isEmpty

  • isEmpty(): boolean

keys

  • keys(): K[]

maxValue

  • maxValue(): null | V
  • Returns the value within the tree that ranks highest, or null if the tree is empty.

    Returns null | V

minValue

  • minValue(): null | V
  • Returns the value within the tree that ranks lowest, or null if the tree is empty.

    Returns null | V

search

  • search(key: K): null | V
  • Search a value by a given searchKey, matching against keys of nodes.

    Parameters

    • key: K

    Returns null | V

    The matching value contained in the tree, or null if the key is not in the tree.

size

  • size(): number

Private toArray

  • toArray<T>(transformer: (node: AVLNode<K, V>) => T): T[]

values

  • values(): V[]