public class MinHeapWithUpdate extends Object
This class is very similar to IntFloatBinaryHeap
, but compared to this has an efficient update operation.
In turn it is (much) less memory-efficient when the heap is used for a small number of elements from a large range.
Constructor and Description |
---|
MinHeapWithUpdate(int elements) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
contains(int id) |
boolean |
isEmpty() |
int |
peekId() |
float |
peekValue() |
int |
poll()
Extracts the element with minimum value from the heap
|
void |
push(int id,
float value)
Adds an element to the heap, the given id must not exceed the size specified in the constructor.
|
int |
size() |
void |
update(int id,
float value)
Updates the element with the given id.
|
public MinHeapWithUpdate(int elements)
elements
- the number of elements that can be stored in this heap. Currently the heap cannot be resized or
shrunk/trimmed after initial creation. elements-1 is the maximum id that can be stored in this
heappublic int size()
public boolean isEmpty()
public void push(int id, float value)
update(int, float)
method.public boolean contains(int id)
public void update(int id, float value)
contains(int)
to check the existence
of an id.public int peekId()
public float peekValue()
public int poll()
public void clear()
Copyright © 2012–2021. All rights reserved.