FSharpx.Collections


Heap<'T> Type

Heap is an ordered linear structure where the ordering is either ascending or descending. "head" inspects the first element in the ordering, "tail" takes the remaining structure after head, and "insert" places elements within the ordering. PriorityQueue is available as an alternate interface. According to Okasaki the time complexity of the heap functions in this Heap implementation (based on the "pairing" heap) have "resisted" time complexity analysis.

Constructors

Constructor Description

Heap(isDescending, length, data)

Full Usage: Heap(isDescending, length, data)

Parameters:
    isDescending : bool
    length : int
    data : HeapData<'T>

Returns: Heap<'T>
isDescending : bool
length : int
data : HeapData<'T>
Returns: Heap<'T>

Instance members

Instance member Description

this.Head

Full Usage: this.Head

Returns: 'T

O(1) worst case. Returns the min or max element.

Returns: 'T

this.Insert(x)

Full Usage: this.Insert(x)

Parameters:
    x : 'T

Returns: Heap<'T>

O(log n) amortized time. Returns a new heap with the element inserted.

x : 'T
Returns: Heap<'T>

this.IsDescending

Full Usage: this.IsDescending

Returns: bool

O(1). Returns true if the heap has max element at head.

Returns: bool

this.IsEmpty

Full Usage: this.IsEmpty

Returns: bool

O(1). Returns true if the heap has no elements.

Returns: bool

this.Length

Full Usage: this.Length

Returns: int

O(1). Returns the count of elememts.

Returns: int

this.Merge(xs)

Full Usage: this.Merge(xs)

Parameters:
Returns: Heap<'T>

O(log n) amortized time. Returns heap from merging two heaps, both must have same descending.

xs : Heap<'T>
Returns: Heap<'T>

this.Rev()

Full Usage: this.Rev()

Returns: Heap<'T>

O(n log n). Returns heap reversed.

Returns: Heap<'T>

this.Tail()

Full Usage: this.Tail()

Returns: Heap<'T>

O(log n) amortized time. Returns a new heap of the elements trailing the head.

Returns: Heap<'T>

this.TryHead

Full Usage: this.TryHead

Returns: 'T option

O(1) worst case. Returns option first min or max element.

Returns: 'T option

this.TryMerge(xs)

Full Usage: this.TryMerge(xs)

Parameters:
Returns: Heap<'T> option

O(log n) amortized time. Returns heap option from merging two heaps.

xs : Heap<'T>
Returns: Heap<'T> option

this.TryTail()

Full Usage: this.TryTail()

Returns: Heap<'T> option

O(log n) amortized time. Returns option heap of the elements trailing the head.

Returns: Heap<'T> option

this.TryUncons()

Full Usage: this.TryUncons()

Returns: ('T * Heap<'T>) option

O(log n) amortized time. Returns option head element and tail.

Returns: ('T * Heap<'T>) option

this.Uncons()

Full Usage: this.Uncons()

Returns: 'T * Heap<'T>

O(log n) amortized time. Returns the head element and tail.

Returns: 'T * Heap<'T>