decrease_key-methods: Decreases the key of a node in a heap

Description Usage Arguments Value Examples

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

1
2
3
4
5
6
7
decrease_key(obj, from, to, handle)

## S4 method for signature 'heap,vector,vector,character'
decrease_key(obj, from, to, handle)

## S4 method for signature '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 # 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)

datastructures documentation built on Aug. 10, 2020, 5:08 p.m.