|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object heaps.mapping.MappingHeap<K,V> heaps.mapping.ArrayBackedMappingHeap<K,V>
K
- the type of all keysV
- the type of all valuespublic class ArrayBackedMappingHeap<K,V>
A implementation of the MappingHeap
interface that is only
backed by an array. For an array of N elements, this class executes
the methods of MappingHeap
that depend on the implementation
in O(N) time. These methods are slower than their counterparts
implemented in FastMappingHeap
because existing mappings must
be searched for in the backing array.
Constructor Summary | |
---|---|
ArrayBackedMappingHeap()
Creates a new heap with the backing array having an initial size of 16. |
|
ArrayBackedMappingHeap(java.util.Comparator<? super K> _comp)
Creates a new heap with the backing array having an initial size of 16. |
|
ArrayBackedMappingHeap(java.util.Comparator<? super K> _comp,
int _init_capacity)
Creates a new heap with the backing array having the specified initial size. |
|
ArrayBackedMappingHeap(int _init_capacity)
Creates a new heap with the backing array having the specified initial size. |
Method Summary | |
---|---|
void |
clear()
Removes all elements from the heap. |
boolean |
contains(K key)
Returns whether a value is mapped to by the given key. |
MappingHeapEntry<K,V> |
extract()
Extracts the next element from the heap. |
V |
get(K key)
Returns the value that is mapped to by the given key. |
int |
getSize()
Returns the number of elements in the heap. |
boolean |
isEmpty()
Returns true if the heap is empty, false
otherwise. |
V |
put(K key,
V value)
Creates a mapping from the given key to the given value. |
V |
remove(K key)
Removes the mapping for the given key if one exists. |
MappingHeapEntry<K,V> |
top()
Returns the next object element to be extracted from the heap without actually removing it from the heap. |
Methods inherited from class heaps.mapping.MappingHeap |
---|
getComparator |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ArrayBackedMappingHeap()
Comparable
interface and be mutually
comparable.
public ArrayBackedMappingHeap(int _init_capacity)
Comparable
interface and be
mutually comparable.
_init_capacity
- the initial size of the backing arraypublic ArrayBackedMappingHeap(java.util.Comparator<? super K> _comp)
_comp
- the comparator used to order keyspublic ArrayBackedMappingHeap(java.util.Comparator<? super K> _comp, int _init_capacity)
_comp
- the comparator used to order heap elements_init_capacity
- the initial size of the backing arrayMethod Detail |
---|
public V put(K key, V value)
MappingHeap
put
in class MappingHeap<K,V>
key
- the key to map to the given valuevalue
- the value to be mapped to by the key
null
if no value existedpublic V get(K key)
MappingHeap
null
.
get
in class MappingHeap<K,V>
key
- the key whose associated value is to be returned
public boolean contains(K key)
MappingHeap
contains
in class MappingHeap<K,V>
key
- the key to query for membership of in the heap
true
if the given key maps to a value,
false
otherwisepublic V remove(K key)
MappingHeap
null
and has no effect.
remove
in class MappingHeap<K,V>
key
- the key to remove a mapping under
null
if
the key maps to no valuepublic void clear()
Heap
public MappingHeapEntry<K,V> top()
Heap
Comparable
. If the heap is
empty, null
is returned.
public MappingHeapEntry<K,V> extract()
Heap
Comparable
. If the
heap is empty, null
is returned.
public int getSize()
Heap
public boolean isEmpty()
Heap
true
if the heap is empty, false
otherwise. This is equivalent to returning true if and only if
getSize
returns 0
.
true
if the heap is empty, false
otherwise
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |