Learn R Programming

datastructures (version 0.2.9)

decrease_key: Decreases the key of a node in a heap

Description

Decreases 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.

Usage

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)

Arguments

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

Value

returns extracted handles and values from obj

Examples

Run this code
# NOT RUN {
 # decreases the key of a heap
 f_heap <- fibonacci_heap("integer")
 f_heap <- insert(f_heap, 1:5, letters[1:5])
 peek(f_heap)

 decrease_key(f_heap, 5L, -1L)
 peek(f_heap)

 hand <- handle(f_heap, value=letters[3])
 decrease_key(f_heap, hand[[1]]$key, -2L)
 peek(f_heap)

# }

Run the code above in your browser using DataLab