Heap

A heap is a special kind of binary tree in which every node is greater than all of its children.  The implementation is based on an arrayed binary tree.  It can be used as an efficient priority queue.

See Also

PriorityQueue

Summary
HeapA heap is a special kind of binary tree in which every node is greater than all of its children.
Functions and Properties
HeapInitializes a new heap.
frontThe heap’s front item.
maxSizeThe heap’s maximum capacity.
enqueueEnqueues some data.
dequeueDequeues and returns the front item.
containsChecks if a given item exists.
clear@inheritDoc
getIterator@inheritDoc
size@inheritDoc
isEmpty@inheritDoc
toArray@inheritDoc
toStringPrints out a string representing the current object.
dumpPrints out all elements (for debug/demo purposes).

Functions and Properties

Heap

public function Heap(size: int,  
compare: Function = null)

Initializes a new heap.

Parameters

sizeThe heap’s maximum capacity.
compareA comparison function for sorting the heap’s data.  If no function is passed, the heap uses a function for comparing numbers. 

front

public function get front():*

The heap’s front item.

maxSize

public function get maxSize():int

The heap’s maximum capacity.

enqueue

public function enqueue(obj: *):Boolean

Enqueues some data.

Parameters

objThe data to enqueue.

Returns

False if the queue is full, otherwise true. 

dequeue

public function dequeue():*

Dequeues and returns the front item.

Returns

The heap’s front item or null if it is empty. 

contains

public function contains(obj: *):Boolean

Checks if a given item exists.

Returns

True if the item is found, otherwise false. 

clear

public function clear():void

@inheritDoc

getIterator

public function getIterator():Iterator

@inheritDoc

size

public function get size():int

@inheritDoc

isEmpty

public function isEmpty():Boolean

@inheritDoc

toArray

public function toArray():Array

@inheritDoc

toString

public function toString():String

Prints out a string representing the current object.

Returns

A string representing the current object. 

dump

public function dump():String

Prints out all elements (for debug/demo purposes).

Returns

A human-readable representation of the structure. 

A ‘java-style’ collection interface.
public function Heap(size: int,  
compare: Function = null)
Initializes a new heap.
public function get front():*
The heap’s front item.
public function get maxSize():int
The heap’s maximum capacity.
public function enqueue(obj: *):Boolean
Enqueues some data.
public function dequeue():*
Dequeues and returns the front item.
public function contains(obj: *):Boolean
Checks if a given item exists.
public function clear():void
@inheritDoc
public function getIterator():Iterator
@inheritDoc
public function get size():int
@inheritDoc
public function isEmpty():Boolean
@inheritDoc
public function toArray():Array
@inheritDoc
public function toString():String
Prints out a string representing the current object.
public function dump():String
Prints out all elements (for debug/demo purposes).
A priority queue to manage prioritized data.
Close