站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 common API Documentation 英文版文档

Heap (JBoss/Common API) - JBoss 4.0.1 sp1 common API Documentation 英文版文档


org.jboss.util
Class Heap

java.lang.Object
  extended byorg.jboss.util.Heap

public class Heap
extends Object

Data structure that mantains data in a ordered binary tree; each node is greater (smaller) or equal than its 2 sub-nodes, for all the hierarchy.

Elements of this data structure should either implement Comparable, or a Comparator should be given as argument to the constructor.

Version:
$Revision: 1.1 $
Author:
Simone Bordet

Constructor Summary
Heap()
          Creates a new Heap whose elements inserted implement the Comparable interface.
Heap(Comparator comparator)
          Creates a new Heap whose elements are compared using the given Comparator.
 
Method Summary
 void clear()
          Empties this heap
protected  int compare(Object o1, Object o2)
          Compares the given objects using the comparator, if available, or considering them Comparable objects.
 Object extract()
          Removes and returns the least element of this heap.
 void insert(Object obj)
          Inserts the given element in this heap.
protected  int left(int index)
          Returns the left child index of index.
protected  int parent(int index)
          Returns the parent index of index.
 Object peek()
          Returns, without removing it, the least element of this heap.
protected  int right(int index)
          Returns the right child index of index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Heap

public Heap()
Creates a new Heap whose elements inserted implement the Comparable interface.


Heap

public Heap(Comparator comparator)
Creates a new Heap whose elements are compared using the given Comparator.

Method Detail

insert

public void insert(Object obj)
Inserts the given element in this heap.

See Also:
extract()

extract

public Object extract()
Removes and returns the least element of this heap.

See Also:
insert(java.lang.Object), peek()

peek

public Object peek()
Returns, without removing it, the least element of this heap.

See Also:
extract()

clear

public void clear()
Empties this heap


compare

protected int compare(Object o1,
                      Object o2)
Compares the given objects using the comparator, if available, or considering them Comparable objects.

Throws:
ClassCastException - if nor the comparator is given and nor both objects implements the Comparable interface

parent

protected int parent(int index)
Returns the parent index of index.


left

protected int left(int index)
Returns the left child index of index.


right

protected int right(int index)
Returns the right child index of index.



Copyright © 2002 JBoss Group, LLC. All Rights Reserved.