insert-methods: Add elements to an object

Description Usage Arguments Value Examples

Description

Adds keys or <key, value> pairs to an object and returns the object. Depending on the datastructure used, either only keys are required or pairs of <keys, values>. Insertion of elements with vectors, i.e. giving multiple arguments at the same time is faster than inserting elements iteratively.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
insert(obj, x, y)

## S4 method for signature 'deque,ANY,missing'
insert(obj, x)

## S4 method for signature 'deque,list,missing'
insert(obj, x)

## S4 method for signature 'heap,vector,vector'
insert(obj, x, y)

## S4 method for signature 'heap,vector,matrix'
insert(obj, x, y)

## S4 method for signature 'heap,vector,list'
insert(obj, x, y)

## S4 method for signature 'heap,vector,ANY'
insert(obj, x, y)

## S4 method for signature 'bimap,vector,vector'
insert(obj, x, y)

## S4 method for signature 'unordered_map,vector,vector'
insert(obj, x, y)

## S4 method for signature 'unordered_map,vector,list'
insert(obj, x, y)

## S4 method for signature 'unordered_map,vector,ANY'
insert(obj, x, y)

Arguments

obj

object to insert into

x

the values/keys to insert into

y

values to be inserted which are required for some datastructures

Value

returns obj with inserted values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
 # inserts values into a multimap
 m_map <- multimap()
 m_map <- insert(m_map, c("a", "b"), 1:2)
 m_map <- insert(m_map, c("a", "b"), list(1, list(a=1)))
 m_map["a"] <- rnorm(length(letters))
 m_map[c("a", "b", "c")] <- list(1, data.frame(a=2), environment())

 # inserts values into a fibonacci_heap
 f_heap <- fibonacci_heap("integer")
 f_heap <- insert(f_heap, 1:2, 1:2)
 f_heap[3:4] <- list(1, list(a=1))
 f_heap <- insert(f_heap, 5:6, list(data.frame(a=rnorm(3)), diag(2)))

 # inserts elements into a queue or stack
 s <- stack()
 s <- insert(s, list(1, vector(), list(3), data.frame(rnorm(3))))

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