GODPAPER | All Packages | All Classes | Index | Frames No Frames |
Heap

Package | de.polygonal.ds
Class | public class Heap
Inheritance | Heap Object
Implements | Collection

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

Public Properties

| Property | Defined By
--- | --- | ---
|  | front : * [read-only] The heap's front item. | Heap
|  | _heap : Array | Heap
|  | maxSize : int [read-only] The heap's maximum capacity. | Heap
|  | size : int [read-only] The total number of items. | Heap

Public Methods

| Method | Defined By
--- | --- | ---
|  | Heap(size:int, compare:Function = null) Initializes a new heap. | Heap
|  | clear():void Clears all items. | Heap
|  | contains(obj:*):Boolean Checks if a given item exists. | Heap
|  | dequeue():* Dequeues and returns the front item. | Heap
|  | dump():String Prints out all elements (for debug/demo purposes). | Heap
|  | enqueue(obj:*):Boolean Enqueues some data. | Heap
|  | getIterator():Iterator Initializes an iterator object pointing to the first item in the collection. | Heap
|  | isEmpty():Boolean Checks if the collection is empty. | Heap
|  | toArray():Array Converts the collection into an array. | Heap
|  | toString():String Prints out a string representing the current object. | Heap

Property Detail

_heap | property

`public var _heap:Array`

front | property |

`front:*` [read-only]

The heap's front item.

Implementation
`public function get front():*`

maxSize | property |

`maxSize:int` [read-only]

The heap's maximum capacity.

Implementation
`public function get maxSize():int`

size | property |

`size:int` [read-only]

The total number of items.

Implementation
`public function get size():int`
Constructor Detail

Heap | () | Constructor

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

Initializes a new heap.

Parameters

| `size:int` — The heap's maximum capacity.
| `compare:Function` (default = `null`)`` — A comparison function for sorting the heap's data. If no function is passed, the heap uses a function for comparing numbers.

Method Detail

clear | () | method

`public function clear():void`

Clears all items.

contains | () | method |

`public function contains(obj:*):Boolean`

Checks if a given item exists.

Parameters

| `obj:*`

Returns

| `Boolean` — True if the item is found, otherwise false.

dequeue | () | method |

`public function dequeue():*`

Dequeues and returns the front item.

Returns

| `*` — The heap's front item or null if it is empty.

dump | () | method |

`public function dump():String`

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

Returns

| `String` — A human-readable representation of the structure.

enqueue | () | method |

`public function enqueue(obj:*):Boolean`

Enqueues some data.

Parameters

| `obj:*` — The data to enqueue.

Returns

| `Boolean` — False if the queue is full, otherwise true.

getIterator | () | method |

`public function getIterator():Iterator`

Initializes an iterator object pointing to the first item in the collection.

Returns

| `Iterator` — An iterator object.

isEmpty | () | method |

`public function isEmpty():Boolean`

Checks if the collection is empty.

Returns

| `Boolean` — True if empty, otherwise false.

toArray | () | method |

`public function toArray():Array`

Converts the collection into an array.

Returns

| `Array` — An array.

toString | () | method |

`public function toString():String`

Prints out a string representing the current object.

Returns

| `String` — A string representing the current object.

Thu Jan 16 2014, 01:11 PM +08:00