T - type of the objects in the heappublic abstract class AbstractTopN<T> extends AbstractCollection<T>
| Modifier and Type | Field and Description |
|---|---|
protected int |
capacity
Maximum capacity of the heap.
|
protected int |
size
Current size of the heap.
|
| Constructor and Description |
|---|
AbstractTopN(int capacity)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T elem) |
protected abstract int |
compare(int i,
int j)
Compares the i-th element of the heap with the j-th element in the heap.
|
protected abstract int |
compare(int i,
T e)
Compares the i-th element of the heap with the element
|
protected abstract T |
get(int i)
Returns the i-th element in the heap.
|
Iterator<T> |
iterator() |
T |
peek()
Returns the element at the top of the heap.
|
Iterator<T> |
reverseIterator()
Iterates over the elements of the heap in reverse order.
|
Stream<T> |
reverseStream()
Creates a stream in reverse order.
|
protected abstract void |
set(int i,
T e)
Sets the element in the i-th position of the heap.
|
int |
size() |
void |
sort()
Sorts the heap in inverse order (from smallest to greatest).
|
protected abstract void |
swap(int i,
int j)
Swaps the elements in the i-th and j-th element in the heap.
|
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streamprotected int capacity
protected int size
public AbstractTopN(int capacity)
capacity - maximum capacity of the heappublic int size()
size in interface Collection<T>size in class AbstractCollection<T>public T peek()
public boolean add(T elem)
add in interface Collection<T>add in class AbstractCollection<T>public void sort()
public Iterator<T> iterator()
iterator in interface Iterable<T>iterator in interface Collection<T>iterator in class AbstractCollection<T>public Iterator<T> reverseIterator()
public Stream<T> reverseStream()
protected abstract T get(int i)
i - index of the elementprotected abstract void set(int i,
T e)
i - indexe - elementprotected abstract int compare(int i,
T e)
i - indexe - elementprotected abstract int compare(int i,
int j)
i - indexj - indexprotected abstract void swap(int i,
int j)
i - indexj - indexCopyright © 2016. All rights reserved.