Package org.tinspin.index.util
Class MinMaxHeap<T>
- java.lang.Object
-
- org.tinspin.index.util.MinMaxHeap<T>
-
- Type Parameters:
T- Entry type
- All Implemented Interfaces:
MinMaxHeapI<T>
public class MinMaxHeap<T> extends Object implements MinMaxHeapI<T>
Min-max heap implementation based on: https://en.wikipedia.org/wiki/Min-max_heap
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMinMaxHeap.Less<T>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()static <T extends Comparable<T>>
MinMaxHeap<T>create()WARNING: This is slow, seecreate(Less).static <T> MinMaxHeap<T>create(MinMaxHeap.Less<T> less)Providing a less() method is the preferred way to use this MinMaxHeap.static <T> MinMaxHeap<T>createWithComparator(Comparator<T> compareFn)WARNING: This is slow, seecreate(Less).booleanisEmpty()TpeekMax()TpeekMin()voidpopMax()voidpopMin()Stringprint()voidpush(T value)intsize()
-
-
-
Method Detail
-
create
public static <T extends Comparable<T>> MinMaxHeap<T> create()
WARNING: This is slow, seecreate(Less). Creates a new MinMaxHeap using the compareTo method of the provided entry type.- Type Parameters:
T- The entry type. Must implementComparable<T>.- Returns:
- A new MinMaxHeap
-
createWithComparator
public static <T> MinMaxHeap<T> createWithComparator(Comparator<T> compareFn)
WARNING: This is slow, seecreate(Less). Creates a new MinMaxHeap using the provided comparator for entries.- Type Parameters:
T- The entry type.- Parameters:
compareFn- Comparator for T- Returns:
- A new MinMaxHeap
-
create
public static <T> MinMaxHeap<T> create(MinMaxHeap.Less<T> less)
Providing a less() method is the preferred way to use this MinMaxHeap. Using less() is about 20% faster than using Comparator/Comparable.- Type Parameters:
T- The entry type.- Parameters:
less- A method that return `true` if the first parameter is less than the second- Returns:
- A new MinMaxHeap
-
push
public void push(T value)
- Specified by:
pushin interfaceMinMaxHeapI<T>
-
popMin
public void popMin()
- Specified by:
popMinin interfaceMinMaxHeapI<T>
-
popMax
public void popMax()
- Specified by:
popMaxin interfaceMinMaxHeapI<T>
-
peekMin
public T peekMin()
- Specified by:
peekMinin interfaceMinMaxHeapI<T>
-
peekMax
public T peekMax()
- Specified by:
peekMaxin interfaceMinMaxHeapI<T>
-
size
public int size()
- Specified by:
sizein interfaceMinMaxHeapI<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMinMaxHeapI<T>
-
print
public String print()
-
clear
public void clear()
- Specified by:
clearin interfaceMinMaxHeapI<T>
-
-