opennlp.tools.util
Class ListHeap<E extends Comparable<E>>

java.lang.Object
  extended by opennlp.tools.util.ListHeap<E>
All Implemented Interfaces:
Heap<E>

public class ListHeap<E extends Comparable<E>>
extends Object
implements Heap<E>

This class implements the heap interface using a List as the underlying data structure. This heap allows values which are equals to be inserted. The heap will return the top K values which have been added where K is specified by the size passed to the constructor. K+1 values are not gaurenteed to be kept in the heap or returned in a particular order.


Constructor Summary
ListHeap(int sz)
          Creates a new heap of the specified size.
ListHeap(int sz, Comparator<E> c)
          Creates a new heap with the specified size using the sorted based on the specified comparator.
 
Method Summary
 void add(E o)
          Adds the specified object to the heap.
 void clear()
          Clears the contents of the heap.
 E extract()
          Removes the smallest element from the heap and returns it.
 E first()
          Returns the smallest element of the heap.
 boolean isEmpty()
          Returns whether the heap is empty.
 Iterator<E> iterator()
          Returns an iterator over the elements of the heap.
 E last()
          Returns the largest element of the heap.
static void main(String[] args)
          Deprecated. 
 int size()
          Returns the size of the heap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListHeap

public ListHeap(int sz,
                Comparator<E> c)
Creates a new heap with the specified size using the sorted based on the specified comparator.

Parameters:
sz - The size of the heap.
c - The comparator to be used to sort heap elements.

ListHeap

public ListHeap(int sz)
Creates a new heap of the specified size.

Parameters:
sz - The size of the new heap.
Method Detail

size

public int size()
Description copied from interface: Heap
Returns the size of the heap.

Specified by:
size in interface Heap<E extends Comparable<E>>
Returns:
The size of the heap.

extract

public E extract()
Description copied from interface: Heap
Removes the smallest element from the heap and returns it.

Specified by:
extract in interface Heap<E extends Comparable<E>>
Returns:
The smallest element from the heap.

first

public E first()
Description copied from interface: Heap
Returns the smallest element of the heap.

Specified by:
first in interface Heap<E extends Comparable<E>>
Returns:
The top element of the heap.

last

public E last()
Description copied from interface: Heap
Returns the largest element of the heap.

Specified by:
last in interface Heap<E extends Comparable<E>>
Returns:
The largest element of the heap.

add

public void add(E o)
Description copied from interface: Heap
Adds the specified object to the heap.

Specified by:
add in interface Heap<E extends Comparable<E>>
Parameters:
o - The object to add to the heap.

clear

public void clear()
Description copied from interface: Heap
Clears the contents of the heap.

Specified by:
clear in interface Heap<E extends Comparable<E>>

iterator

public Iterator<E> iterator()
Description copied from interface: Heap
Returns an iterator over the elements of the heap. No specific ordering of these elements is guaranteed.

Specified by:
iterator in interface Heap<E extends Comparable<E>>
Returns:
An iterator over the elements of the heap.

isEmpty

public boolean isEmpty()
Description copied from interface: Heap
Returns whether the heap is empty.

Specified by:
isEmpty in interface Heap<E extends Comparable<E>>
Returns:
true if the heap is empty; false otherwise.

main

@Deprecated
public static void main(String[] args)
Deprecated. 



Copyright © 2010. All Rights Reserved.