Packagech.capi.data.tree
Classpublic class ArrayHeap
ImplementsIHeap

Default implementation of a IHeap.



Public Properties
 PropertyDefined by
  nextElement : *
[read-only] Defines the next element that will be removed from the data structure.
ArrayHeap
  sortFunction : Function
[read-only] Defines the sort function that will be used to sort the items.
ArrayHeap
Public Methods
 MethodDefined by
  
ArrayHeap(sortFunction:Function)
Creates a new ArrayHeap object.
ArrayHeap
  
add(element:*):void
Add an element to the data structure.
ArrayHeap
  
clear():void
Removes all the elements from the data structure.
ArrayHeap
  
contains(element:*):Boolean
Retrieves if the specified element is contained into the ArrayHeap.
ArrayHeap
  
getDepth():uint
Retrieves the depth of the Heap.
ArrayHeap
  
getElementDepth(element:*):int
Retrieves the depth of an alement.
ArrayHeap
  
isEmpty():Boolean
Get if the structure is empty or not.
ArrayHeap
  
remove():*
Removes an element from the data structure.
ArrayHeap
Property detail
nextElementproperty
nextElement:*  [read-only]

Defines the next element that will be removed from the data structure.

Implementation
    public function get nextElement():*
sortFunctionproperty 
sortFunction:Function  [read-only]

Defines the sort function that will be used to sort the items. The sort function must take two parameters and return an int value comparing it.

Implementation
    public function get sortFunction():Function

Example
   var f:Function = function(a:int, b:int):int
   {
     return b-a;
   }
   
   var h:ArrayHeap = new ArrayHeap(f);
   h.add(5);
   h.add(4);
   h.add(6);
   h.add(2);
   while (!h.isEmpty()) trace(h.remove);
   

Constructor detail
ArrayHeap()constructor
public function ArrayHeap(sortFunction:Function)

Creates a new ArrayHeap object.

Parameters
sortFunction:Function — The sort function.
Method detail
add()method
public function add(element:*):void

Add an element to the data structure.

Parameters
element:* — The element to add.
clear()method 
public function clear():void

Removes all the elements from the data structure.

contains()method 
public function contains(element:*):Boolean

Retrieves if the specified element is contained into the ArrayHeap.

Parameters
element:* — The element.

Returns
Booleantrue if the element is contained into the ArrayHeap.
getDepth()method 
public function getDepth():uint

Retrieves the depth of the Heap.

Returns
uint — The depth.
getElementDepth()method 
public function getElementDepth(element:*):int

Retrieves the depth of an alement. If the specified element is not into the ArrayHeap, then -1 is returned.

Parameters
element:* — element The element.

Returns
int — The element depth or -1.
isEmpty()method 
public function isEmpty():Boolean

Get if the structure is empty or not.

Returns
Booleantrue if there is no element into the structure.
remove()method 
public function remove():*

Removes an element from the data structure.

Returns
* — The element removed.