Options
All
  • Public
  • Public/Protected
  • All
Menu

The creation methods for IAVLTree instances.

Hierarchy

  • AVLTreeFactories

Index

Methods

Methods

create

  • Build an AVL tree for complex values. Requires a getKey function that takes such a complex value, and returns the key by which that value is identified.

    example
    
    import AVLTree, { IAVLTree } from 'avl-bst'
    
    interface Foo {
        id: number
    }
    
    // Note: there are multiple ways the types can be specified - pick your poison :)
    
    // 1. using a type guard (note the additional interface import)
    const myTree: IAVLTree<number, Foo> = AVLTree.create((foo) => foo.id)
    
    // 2. using explicit arguments
    const myTree = AVLTree.create<number, Foo>((foo) => foo.id)
    
    // 3. inferred from the given function
    const myTree = AVLTree.create((foo: Foo) => foo.id)
    

    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.

    Parameters

    • getKey: GetKey<K, V>

      The function that derives the key of a given value of type V

    Returns IAVLTree<K, V>

scalar

  • Build an AVL tree for scalar - orderable - values. Note that (in typescript) the type argument for the scalar type is required for successive operations to properly type-check.

    example
    const scalarTree = AVLTree.scalar<number>()
    

    Type parameters

    • V: Ord

      The (scalar, orderable) type of tree values.

    Returns IAVLTree<V, V>