Java Doc for BinaryHeap.java in  » Library » Apache-common-Collections » org » apache » commons » collections » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common Collections » org.apache.commons.collections 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.AbstractCollection
      org.apache.commons.collections.BinaryHeap

BinaryHeap
final public class BinaryHeap extends AbstractCollection implements PriorityQueue,Buffer(Code)
Binary heap implementation of PriorityQueue.

The PriorityQueue interface has now been replaced for most uses by the Buffer interface. This class and the interface are retained for backwards compatibility. The intended replacement is org.apache.commons.collections.buffer.PriorityBuffer PriorityBuffer .

The removal order of a binary heap is based on either the natural sort order of its elements or a specified Comparator . The BinaryHeap.pop() method always returns the first element as determined by the sort order. (The isMinHeap flag in the constructors can be used to reverse the sort order, in which case BinaryHeap.pop() will always remove the last element.) The removal order is not the same as the order of iteration; elements are returned by the iterator in no particular order.

The BinaryHeap.insert(Object) and BinaryHeap.pop() operations perform in logarithmic time. The BinaryHeap.peek() operation performs in constant time. All other operations perform in linear time or worse.

Note that this implementation is not synchronized. Use SynchronizedPriorityQueue to provide synchronized access to a BinaryHeap:

 PriorityQueue heap = new SynchronizedPriorityQueue(new BinaryHeap());
 

since:
   Commons Collections 1.0
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   Peter Donald
author:
   Ram Chidambaram
author:
   Michael A. Smith
author:
   Paul Jack
author:
   Stephen Colebourne


Field Summary
 Comparatorm_comparator
    
 Object[]m_elements
     The elements in this heap.
 booleanm_isMinHeap
     If true, the first element as determined by the sort order will be returned.
 intm_size
     The number of elements currently in this heap.

Constructor Summary
public  BinaryHeap()
     Constructs a new minimum binary heap.
public  BinaryHeap(Comparator comparator)
     Constructs a new BinaryHeap that will use the given comparator to order its elements.
public  BinaryHeap(int capacity)
     Constructs a new minimum binary heap with the specified initial capacity.
Parameters:
  capacity - The initial capacity for the heap.
public  BinaryHeap(int capacity, Comparator comparator)
     Constructs a new BinaryHeap.
public  BinaryHeap(boolean isMinHeap)
    
public  BinaryHeap(boolean isMinHeap, Comparator comparator)
     Constructs a new BinaryHeap.
public  BinaryHeap(int capacity, boolean isMinHeap)
     Constructs a new minimum or maximum binary heap with the specified initial capacity.
Parameters:
  capacity - the initial capacity for the heap.
public  BinaryHeap(int capacity, boolean isMinHeap, Comparator comparator)
     Constructs a new BinaryHeap.

Method Summary
public  booleanadd(Object object)
     Adds an object to this heap.
public  voidclear()
     Clears all elements from queue.
public  Objectget()
     Returns the priority element.
protected  voidgrow()
    
public  voidinsert(Object element)
     Inserts an element into queue.
public  booleanisEmpty()
     Tests if queue is empty.
public  booleanisFull()
     Tests if queue is full.
public  Iteratoriterator()
     Returns an iterator over this heap's elements.
public  Objectpeek()
     Returns the element on top of heap but don't remove it.
protected  voidpercolateDownMaxHeap(int index)
     Percolates element down heap from the position given by the index.
protected  voidpercolateDownMinHeap(int index)
     Percolates element down heap from the position given by the index.
protected  voidpercolateUpMaxHeap(int index)
     Percolates element up heap from from the position given by the index.
protected  voidpercolateUpMaxHeap(Object element)
     Percolates a new element up heap from the bottom.
protected  voidpercolateUpMinHeap(int index)
     Percolates element up heap from the position given by the index.
protected  voidpercolateUpMinHeap(Object element)
     Percolates a new element up heap from the bottom.
public  Objectpop()
     Returns the element on top of heap and remove it.
public  Objectremove()
     Removes the priority element.
public  intsize()
     Returns the number of elements in this heap.
public  StringtoString()
     Returns a string representation of this heap.

Field Detail
m_comparator
Comparator m_comparator(Code)
The comparator used to order the elements



m_elements
Object[] m_elements(Code)
The elements in this heap.



m_isMinHeap
boolean m_isMinHeap(Code)
If true, the first element as determined by the sort order will be returned. If false, the last element as determined by the sort order will be returned.



m_size
int m_size(Code)
The number of elements currently in this heap.




Constructor Detail
BinaryHeap
public BinaryHeap()(Code)
Constructs a new minimum binary heap.



BinaryHeap
public BinaryHeap(Comparator comparator)(Code)
Constructs a new BinaryHeap that will use the given comparator to order its elements.
Parameters:
  comparator - the comparator used to order the elements, nullmeans use natural order



BinaryHeap
public BinaryHeap(int capacity)(Code)
Constructs a new minimum binary heap with the specified initial capacity.
Parameters:
  capacity - The initial capacity for the heap. This value mustbe greater than zero.
throws:
  IllegalArgumentException - if capacity is <= 0



BinaryHeap
public BinaryHeap(int capacity, Comparator comparator)(Code)
Constructs a new BinaryHeap.
Parameters:
  capacity - the initial capacity for the heap
Parameters:
  comparator - the comparator used to order the elements, nullmeans use natural order
throws:
  IllegalArgumentException - if capacity is <= 0



BinaryHeap
public BinaryHeap(boolean isMinHeap)(Code)
Constructs a new minimum or maximum binary heap
Parameters:
  isMinHeap - if true the heap is created as a minimum heap; otherwise, the heap is created as a maximum heap



BinaryHeap
public BinaryHeap(boolean isMinHeap, Comparator comparator)(Code)
Constructs a new BinaryHeap.
Parameters:
  isMinHeap - true to use the order imposed by the given comparator; false to reverse that order
Parameters:
  comparator - the comparator used to order the elements, nullmeans use natural order



BinaryHeap
public BinaryHeap(int capacity, boolean isMinHeap)(Code)
Constructs a new minimum or maximum binary heap with the specified initial capacity.
Parameters:
  capacity - the initial capacity for the heap. This value must be greater than zero.
Parameters:
  isMinHeap - if true the heap is created as a minimum heap; otherwise, the heap is created as a maximum heap.
throws:
  IllegalArgumentException - if capacity is <= 0



BinaryHeap
public BinaryHeap(int capacity, boolean isMinHeap, Comparator comparator)(Code)
Constructs a new BinaryHeap.
Parameters:
  capacity - the initial capacity for the heap
Parameters:
  isMinHeap - true to use the order imposed by the given comparator; false to reverse that order
Parameters:
  comparator - the comparator used to order the elements, nullmeans use natural order
throws:
  IllegalArgumentException - if capacity is <= 0




Method Detail
add
public boolean add(Object object)(Code)
Adds an object to this heap. Same as BinaryHeap.insert(Object) .
Parameters:
  object - the object to add true, always



clear
public void clear()(Code)
Clears all elements from queue.



get
public Object get()(Code)
Returns the priority element. Same as BinaryHeap.peek() . the priority element
throws:
  BufferUnderflowException - if this heap is empty



grow
protected void grow()(Code)
Increases the size of the heap to support additional elements



insert
public void insert(Object element)(Code)
Inserts an element into queue.
Parameters:
  element - the element to be inserted



isEmpty
public boolean isEmpty()(Code)
Tests if queue is empty. true if queue is empty; false otherwise.



isFull
public boolean isFull()(Code)
Tests if queue is full. true if queue is full; falseotherwise.



iterator
public Iterator iterator()(Code)
Returns an iterator over this heap's elements. an iterator over this heap's elements



peek
public Object peek() throws NoSuchElementException(Code)
Returns the element on top of heap but don't remove it. the element at top of heap
throws:
  NoSuchElementException - if isEmpty() == true



percolateDownMaxHeap
protected void percolateDownMaxHeap(int index)(Code)
Percolates element down heap from the position given by the index.

Assumes it is a maximum heap.
Parameters:
  index - the index of the element




percolateDownMinHeap
protected void percolateDownMinHeap(int index)(Code)
Percolates element down heap from the position given by the index.

Assumes it is a minimum heap.
Parameters:
  index - the index for the element




percolateUpMaxHeap
protected void percolateUpMaxHeap(int index)(Code)
Percolates element up heap from from the position given by the index.

Assume it is a maximum heap.
Parameters:
  index - the index of the element to be percolated up




percolateUpMaxHeap
protected void percolateUpMaxHeap(Object element)(Code)
Percolates a new element up heap from the bottom.

Assume it is a maximum heap.
Parameters:
  element - the element




percolateUpMinHeap
protected void percolateUpMinHeap(int index)(Code)
Percolates element up heap from the position given by the index.

Assumes it is a minimum heap.
Parameters:
  index - the index of the element to be percolated up




percolateUpMinHeap
protected void percolateUpMinHeap(Object element)(Code)
Percolates a new element up heap from the bottom.

Assumes it is a minimum heap.
Parameters:
  element - the element




pop
public Object pop() throws NoSuchElementException(Code)
Returns the element on top of heap and remove it. the element at top of heap
throws:
  NoSuchElementException - if isEmpty() == true



remove
public Object remove()(Code)
Removes the priority element. Same as BinaryHeap.pop() . the removed priority element
throws:
  BufferUnderflowException - if this heap is empty



size
public int size()(Code)
Returns the number of elements in this heap. the number of elements in this heap



toString
public String toString()(Code)
Returns a string representation of this heap. The returned string is similar to those produced by standard JDK collections. a string representation of this heap



Methods inherited from java.util.AbstractCollection
public boolean add(E e)(Code)(Java Doc)
public boolean addAll(Collection<? extends E> c)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
public boolean contains(Object o)(Code)(Java Doc)
public boolean containsAll(Collection c)(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
abstract public Iterator<E> iterator()(Code)(Java Doc)
public boolean remove(Object o)(Code)(Java Doc)
public boolean removeAll(Collection c)(Code)(Java Doc)
public boolean retainAll(Collection c)(Code)(Java Doc)
abstract public int size()(Code)(Java Doc)
public Object[] toArray()(Code)(Java Doc)
public T[] toArray(T[] a)(Code)(Java Doc)
public String toString()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.