Class Treap<T>

Treap data structure combining properties of a Binary Search Tree and a Max Heap. Each node satisfies both the BST property (left < root < right) and the heap property based on priority.

Type Parameters

  • T

    The type of values stored in the Treap.

Constructors

  • Creates a new Treap.

    Type Parameters

    • T

    Parameters

    • OptionalcompareFn: ((a: T, b: T) => number)

      Optional comparison function for custom types.

        • (a, b): number
        • Parameters

          Returns number

    Returns Treap<T>

Methods

  • Deletes a value from the Treap.

    Parameters

    • value: T

      The value to delete.

    Returns boolean

    • True if the deletion was successful, false if the value was not found.
  • Performs an in-order traversal of the Treap for testing or debugging purposes.

    Parameters

    • Optionalnode: TreapNode<T> = ...

      The starting node (default is root).

    • Optionalresult: T[] = []

      Accumulator for traversal result.

    Returns T[]

    • The in-order traversal of the Treap values.
  • Inserts a value into the Treap with a specified priority.

    Parameters

    • value: T

      The value to insert.

    • priority: number

      The priority of the value.

    Returns boolean

    • Always returns true as insertion is successful.
  • Searches for a value in the Treap.

    Parameters

    • value: T

      The value to search for.

    Returns boolean

    • True if the value is found, false otherwise.