cpp_map {cppcontainers} | R Documentation |
Create map
Description
Create a map. Maps are key-value pairs sorted by unique keys.
Usage
cpp_map(keys, values)
Arguments
keys |
An integer, numeric, character, or logical vector. |
values |
An integer, numeric, character, or logical vector. |
Details
Maps are associative containers. They do not provide random access through an index. I.e. m[2]
does not return the second element.
C++ map methods implemented in this package are at, clear, contains, count, emplace, empty, erase, insert, insert_or_assign, max_size, merge, size, and try_emplace. The package also adds the == and [ operators 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 CppMap object referencing a map in C++.
See Also
cpp_unordered_map, cpp_multimap, cpp_unordered_multimap.
Examples
m <- cpp_map(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), 14:16)
m
# [4,1] [5,1.5] [6,2] [14,100] [15,100.1] [16,100.2]
print(m, from = 6)
# [6,2] [14,100] [15,100.1] [16,100.2]
m <- cpp_map(c("world", "hello", "there"), 4:6)
m
# ["hello",5] ["there",6] ["world",4]
erase(m, "there")
m
# ["hello",5] ["world",4]