R/methods_decrease.R, R/ds_heap.R
decrease_key-methods.RdDecreases the key of a node in a heap and updates the complete
heap. The key is decreases from a value to a value by that moving the
node's position in the heap. If a node cannot uniquely be identified using
the to key, a handle needs to be given in addition.
decrease_key(obj, from, to, handle) # S4 method for heap,vector,vector,character decrease_key(obj, from, to, handle) # S4 method for heap,vector,vector,missing decrease_key(obj, from, to)
| obj | a heap object |
|---|---|
| from | a key in the heap for which the node should be decreased |
| to | the new value of the heap |
| handle | the handle of the specific node that is decreased |
returns extracted handles and values from obj
# decreases the key of a heap f_heap <- fibonacci_heap("integer") f_heap <- insert(f_heap, 1:5, letters[1:5]) peek(f_heap)#> $`1` #> [1] "a" #>decrease_key(f_heap, 5L, -1L)#> An object of class fibonacci_heap<integer, SEXP> #> #> Peek: -1 -> character, ...peek(f_heap)#> $`-1` #> [1] "e" #>hand <- handle(f_heap, value=letters[3]) decrease_key(f_heap, hand[[1]]$key, -2L)#> An object of class fibonacci_heap<integer, SEXP> #> #> Peek: -2 -> character, ...peek(f_heap)#> $`-2` #> [1] "c" #>