Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IAVLTree<K, V>

The AVL tree's instance interface.

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

  • IAVLTree

Implemented by

Index

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, curr: V) => T, seed: T): T
  • Folds (reduces) the tree left-to-right using in-order traversal.

    Type parameters

    • T

      The type of the accumulation (and the seed).

    Parameters

    • fn: (acc: T, curr: V) => T

      The accumulator function.

        • (acc: T, curr: V): T
        • Parameters

          • acc: T
          • curr: V

          Returns T

    • seed: T

      The initial value.

    Returns T

    The accumulation of the tree.

foldRight

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

    Type parameters

    • T

      The type of the accumulation (and the seed).

    Parameters

    • fn: (acc: T, curr: V) => T

      The accumulator function.

        • (acc: T, curr: V): T
        • Parameters

          • acc: T
          • curr: V

          Returns T

    • seed: T

      The initial value.

    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

      The callback function to run for each value in the tree.

        • (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
  • Returns true if the tree does not have any nodes.

    Returns boolean

keys

  • keys(): K[]
  • Returns a list of all keys within the tree as an array, in-order.

    Returns 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

      The node key - which must be of type K - to look for.

    Returns null | V

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

size

  • size(): number
  • Returns the size of the tree: the amount of nodes contained.

    Returns number

values

  • values(): V[]
  • Returns a list of all values within the tree as an array, in-order.

    Returns V[]