Class SplayTree<K, V>

A splay tree is a self-balancing binary search tree with the additional property that recently accessed elements are quick to access again. Insertion, look-up and removal in O(log n) amortized time. For many patterns of non-random operations splay trees can take better than logarithmic time, without requiring advance knowledge of the pattern.

See

Template

V

Type Parameters

  • K

  • V = any

Hierarchy

Constructors

  • Create a new randomized Splay Tree

    Type Parameters

    • K

    • V = any

    Parameters

    • Optional compareFn: any
    • p: number = 0.5

      When an element is accessed, with probability p splay the tree. With probability 1 - p, leave the tree as it is.

    Returns SplayTree<K, V>

Properties

cmp: Comparer<any>
count: number
randSplay: number
root?: Node<K, V>

Accessors

  • get size(): number
  • Returns the total number of elements in the collection.

    Returns number

Methods

  • Alias of remove but just returns true instead of the deleted value.

    Parameters

    • key: K

    Returns boolean

  • Returns an ordered iterable of all the keys and values in the tree.

    Returns

    A iterable of [key, value] pairs sorted by key.

    Returns Iterable<[K, V]>

  • Returns the value for key or undefined if the key is not found.

    Returns

    The value for the key or undefined.

    Parameters

    • key: K

      The key to find.

    Returns any

  • Returns the largest key that is less than a given key.

    Returns

    The largest key found or undefined.

    Parameters

    • key: any

      The given key

    Returns K | Node<K, V>

  • Returns the maximum key in the tree or subtree.

    Returns

    The maximum key.

    Parameters

    • root: Node<K, V> = ...

    Returns K

  • Returns the minimum key in the tree or subtree.

    Returns

    The minimum key.

    Parameters

    • root: Node<K, V> = ...

    Returns K

  • Removes a specified key if it exists in the tree. The removed value is returned or undefined if not found.

    Returns

    The removed value associated with key.

    Parameters

    • key: K

      The key to remove.

    Returns V

  • Inserts the key and value in the tree if the key does not exist.

    Returns

    Parameters

    • key: K

      A key which can be any comparable value

    • value: V

      A value associated with the key

    Returns void

  • Returns an ordered iterable of all the keys and values in the tree.

    Returns

    A iterable of [key, value] pairs sorted by key.

    Returns Iterable<V>

Generated using TypeDoc