Inserts the given key/value pair into the heap. @param key key @param value value
(final K key, final V value)
| 32 | * @param value value |
| 33 | */ |
| 34 | public void insert(final K key, final V value) { |
| 35 | final int s = size << 1; |
| 36 | if(s == vals.length) vals = Array.copy(vals, new Object[s << 1]); |
| 37 | vals[s] = key; |
| 38 | vals[s + 1] = value; |
| 39 | |
| 40 | // let the inserted value bubble up to its position |
| 41 | int curr = size++, par = (curr - 1) / 2; |
| 42 | while(curr > 0 && compare(curr, par) < 0) { |
| 43 | swap(curr, par); |
| 44 | curr = par; |
| 45 | par = (curr - 1) / 2; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Removes the minimum from this heap. |