cpp_multimap {cppcontainers} | R Documentation |
Create multimap
Description
Create a multimap. Multimaps are key-value pairs sorted by non-unique keys.
Usage
cpp_multimap(keys, values)
Arguments
keys |
An integer, numeric, character, or logical vector. |
values |
An integer, numeric, character, or logical vector. |
Details
Multimaps are associative containers. They do not provide random access through an index. I.e. m[2]
does not return the second element.
C++ multimap methods implemented in this package are clear, contains, count, emplace, empty, erase, insert, max_size, merge, and size. The package also adds the == operator and various helper functions (print, to_r, type).
All object-creating methods in this package begin with cpp_
to avoid clashes with functions from other packages, such as utils::stack
and
base::vector
.
Value
Returns a CppMultimap object referencing a multimap in C++.
See Also
cpp_map, cpp_unordered_map, cpp_unordered_multimap.
Examples
m <- cpp_multimap(4:6, seq.int(1, by = 0.5, length.out = 3L))
m
# [4,1] [5,1.5] [6,2]
insert(m, seq.int(100, by = 0.1, length.out = 3L), 5:7)
m
# [4,1] [5,1.5] [5,100] [6,2] [6,100.1] [7,100.2]
print(m, from = 6)
# [6,2] [6,100.1] [7,100.2]
m <- cpp_multimap(c("world", "hello", "there", "world"), 3:6)
m
# ["hello",4] ["there",5] ["world",3] ["world",6]
erase(m, "world")
m
# ["hello",4] ["there",5]