Options
All
  • Public
  • Public/Protected
  • All
Menu

Implements the AVL Tree data structure for fast insertion and sorting.

license

Copyright Daniel Imms http://www.growingwiththeweb.com. Modified by the Miratope authors. Released under the MIT license. See LICENSE in the project root for details.

Type parameters

  • T

Hierarchy

  • AvlTree

Index

Constructors

constructor

  • new AvlTree(customCompare: ((a: T, b: T) => number) | null): AvlTree

Properties

Private insertedNode

insertedNode: AvlNode<T> | null

Temporary variable for insert. Stores the new inserted node.

Private root

root: AvlNode<T> | null

The root of the AVL tree.

Private size

size: number

The element count of the AVL tree.

Methods

Private _delete

Private _insert

Private compare

  • compare(a: T, b: T): number
  • The default compare function. Can be overwritten in the constructor.

    Parameters

    • a: T

      The first key to compare.

    • b: T

      The second key to compare.

    Returns number

    -1, 0 or 1 depending on whether a is smaller, equal or larger than b, respectively.

contains

  • contains(key: T): boolean
  • Gets whether a node with a specific key is within the tree.

    Parameters

    • key: T

      The key being searched for.

    Returns boolean

    Whether a node with the key exists.

delete

  • delete(key: T): void

findMaximum

  • findMaximum(): T | null

findMaximumNode

  • findMaximumNode(): AvlNode<T> | null

findMinimum

  • findMinimum(): T | null

findMinimumNode

  • findMinimumNode(): AvlNode<T> | null

Private get

getNode

getSize

  • getSize(): number

insert

isEmpty

  • isEmpty(): boolean

next

prev

Static getBalanceState

Static Private maxValueNode

Static Private minValueNode

Generated using TypeDoc, the 1/31/2021 at 6:18:55 AM