Class Heap

Summary

A Heap is a dense binary tree ordered as a priority queue. The priority order is from lowest to highest priority where the priority of two elements can be compared through the results of invoking the operation f on each. The priority operation p defaults to "<" but can be any binary comparison operation.

Both f and p may be any of lang::Closure, procedure, function, integer, or string-invocation symbol. f is invoked with a single argument (a heap element) and p is invoked to compare the results of two calls to f.

Superclasses:
Object

Package:
collection
File:
heap.icn
Methods:
add, gen, get, size, top

Methods inherited from Object:
Type, className, clone, equals, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField, to_string

Fields:
L, f, p

Source code.

Details
Constructor

Heap(S, fVal, pVal)

Parameters:
S
optional list of initial values to insert into heap
fVal
a lang::Closure, procedure, integer, or string-invocation to use in comparisons. When needed, the operation is invoked with a single argument that is a heap element. Defaults to 1 [i.e. the identity operation]
pVal
a lang::Closure, procedure, integer, or string-invocation implementing a comparison operation on the results of invoking fVal on two Heap elements. Defaults to "<"

Construct a Heap.

Methods:

add(a)

Parameter:
a
element to add
Returns:
a

Add a new element to the heap.


gen()

Generates:
the heap elements(non-destructively) in order


get()

Returns:
the next heap element (destructively, in order)


size()

Returns:
the number of heap elements


top()

Returns:
the top of the heap (non-destructively)


Fields:
L

f

p


This page produced by UniDoc on 2021/04/15 @ 23:59:53.