Package jline.util
Class IndexedMinHeap
java.lang.Object
jline.util.IndexedMinHeap
IndexedMinHeap
A min-heap over a fixed set of integer keys 0..n-1, each associated
with a double priority. Supports O(log n) update of any key by index,
and O(1) peek at the minimum.
Typical use in NRM: keys are reaction indices, priorities are absolute
firing times τ_k.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidEstablish heap order after bulk-writing into key[] directly.doublegetKey(int k) Read the current priority of reaction k.intpeekMin()Return the index of the reaction with the smallest key.doubleReturn the smallest key value.voidupdate(int k, double newKey) Update the priority of reaction k and restore heap order.
-
Field Details
-
key
public final double[] key
-
-
Constructor Details
-
IndexedMinHeap
public IndexedMinHeap(int n) Construct a heap of size n. All keys initialised to +∞. Bulk-set key[] then call buildHeap(), or call update() individually.
-
-
Method Details
-
peekMin
public int peekMin()Return the index of the reaction with the smallest key. O(1). -
peekMinKey
public double peekMinKey()Return the smallest key value. O(1). -
update
public void update(int k, double newKey) Update the priority of reaction k and restore heap order. O(log n). -
getKey
public double getKey(int k) Read the current priority of reaction k. O(1). -
buildHeap
public void buildHeap()Establish heap order after bulk-writing into key[] directly. Runs in O(n) — prefer this over n individual update() calls at init.
-