avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections BinaryHeap.java
Date Tue, 27 Nov 2001 11:29:42 GMT
donaldp     01/11/27 03:29:42

  Modified:    src/java/org/apache/avalon/excalibur/collections
                        BinaryHeap.java
  Log:
  Made comparators public and refactored isMinHeap constructor to chain to other constructor.
  
  Submitted By: "Chad Stansbury" <stansburyc@earthlink.net>
  
  Revision  Changes    Path
  1.6       +31 -8     jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/BinaryHeap.java
  
  Index: BinaryHeap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/BinaryHeap.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BinaryHeap.java	2001/11/19 12:08:46	1.5
  +++ BinaryHeap.java	2001/11/27 11:29:42	1.6
  @@ -18,7 +18,7 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:ram.chidambaram@telus.com">Ram Chidambaram</a>
    * @author <a href="mailto:stansburyc@earthlink.net">Chad Stansbury</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2001/11/19 12:08:46 $
  + * @version CVS $Revision: 1.6 $ $Date: 2001/11/27 11:29:42 $
    * @since 4.0
    */
   public final class BinaryHeap
  @@ -42,8 +42,18 @@
           }
       }
   
  -    private static final Comparator       MIN_COMPARATOR = new MinComparator();
  -    private static final Comparator       MAX_COMPARATOR = new MaxComparator();
  + /**
  +  * Comparator used to instantiate a min heap - assumes contents implement
  +  * the Comparable interface.
  +  */
  +    public static final Comparator        MIN_COMPARATOR = new MinComparator();
  +
  + /**
  +  * Comparator used to instantiate a max heap - assumes contents implement
  +  * the Comparable interface.
  +  */
  +    public static final Comparator        MAX_COMPARATOR = new MaxComparator();
  +
       private static final int              DEFAULT_CAPACITY   = 13;
       private static final Comparator       DEFAULT_COMPARATOR = MIN_COMPARATOR;
       private int                           m_size;
  @@ -60,6 +70,8 @@
   
       /**
        * Instantiates a new min binary heap with the given initial capacity.
  +  *
  +  * @param capacity the size of the heap
        */
       public BinaryHeap( final int capacity )
       {
  @@ -69,6 +81,8 @@
       /**
        * Instantiates a new binary heap with the default initial capacity and
        * ordered using the given Comparator.
  +  *
  +  * @param comparator to order the contents of the heap
        */
       public BinaryHeap( final Comparator comparator )
       {
  @@ -78,6 +92,9 @@
       /**
        * Instantiates a new binary heap with the given initial capacity and
        * ordered using the given Comparator.
  +  *
  +  * @param capacity the size of the heap
  +  * @param comparator to order the contents of the heap
        */
       public BinaryHeap( final int capacity, final Comparator comparator )
       {
  @@ -107,11 +124,7 @@
        */
       public BinaryHeap( final int capacity, final boolean isMinHeap )
       {
  -        //+1 as 0 is noop
  -        m_elements = new Object[ capacity + 1 ];
  -
  -        if( isMinHeap ) m_comparator = MIN_COMPARATOR;
  -        else m_comparator = MAX_COMPARATOR;
  +        this( capacity, isMinHeap ? MIN_COMPARATOR : MAX_COMPARATOR );
       }
   
       /**
  @@ -141,6 +154,16 @@
       {
           //+1 as element 0 is noop
           return ( m_elements.length == m_size+1 );
  +    }
  +
  +    /**
  +     * Returns the number of elements currently on the heap.
  +     *
  +     * @return the size of the heap.
  +     */
  +    public int size()
  +    {
  +        return m_size;
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message