gis-tools-ts - v0.6.0
    Preparing search index...

    Class SplayTreeSet<T>

    Splay Tree Set

    A splay tree set is a self-balancing binary search tree that does not allow duplicate elements. The value of a splay tree is in it's amortized O(log n) for all insert, delete min/max, and find min/max operations.

    import { SplayTreeSet } from 'gis-tools-ts';

    const tree = new SplayTreeSet<number>([], (a, b) => a - b);

    // If the element already exists, the existing element will be returned otherwise
    // the new element will be both added and returned
    let element = tree.add(1);
    tree.add(2);

    console.log(tree.length); // 2
    // Get first and last elements
    let firstElement = tree.first(); // 1
    let lastElement = tree.last(); // 2
    // check if a value exists
    console.log(tree.has(1)); // true
    // look for a value right before one provided
    console.log(tree.lastBefore(2)); // 1
    // look for a value right after one provided
    console.log(tree.firstAfter(1)); // 2

    Type Parameters

    • T
    Index

    Constructors

    Accessors

    • get length(): number

      Returns number

      • the number of elements in the tree

    Methods

    • Add an element

      Parameters

      • element: T

        the element to add

      Returns T

      • the added element OR if the element already exists, the existing element
    • Delete an element. Return the deleted element if it exists otherwise undefined

      Parameters

      • key: T

        the element

      Returns undefined | SplayTreeNode<T>

      • the deleted element
    • Get the first element

      Returns undefined | T

      • the first element, undefined if the queue is empty
    • Get the first element in the set that is strictly larger than element. Returns undefined if no element was not found.

      Parameters

      • element: T

        the element to compare against

      Returns undefined | T

      • the first element after the comparison element provided
    • Check if an element exists

      Parameters

      • key: T

        the element

      Returns boolean

      • true if the element exists
    • Get the last element

      Returns undefined | T

      • the last element, undefined if the queue is empty
    • Get the last element in the set that is strictly smaller than element. Returns undefined if no element was not found.

      Parameters

      • element: T

        the element to compare against

      Returns undefined | T

      • the last element before the comparison element provided