cpp_unordered_map {cppcontainers}R Documentation

Create unordered map

Description

Create an unordered map. Unordered maps are key-value pairs with unique keys.

Usage

cpp_unordered_map(keys, values)

Arguments

keys

An integer, numeric, character, or logical vector.

values

An integer, numeric, character, or logical vector.

Details

Unordered maps are associative containers. They do not provide random access through an index. I.e. m[2] does not return the second element.

Unordered means that the container does not enforce elements to be stored in a particular order. This makes unordered maps in some applications faster than maps.

C++ unordered_map methods implemented in this package are at, bucket_count, clear, contains, count, emplace, empty, erase, insert, insert_or_assign, load_factor, max_bucket_count, max_load_factor, max_size, merge, rehash, reserve, 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 CppUnorderedMap object referencing an unordered_map in C++.

See Also

cpp_map, cpp_multimap, cpp_unordered_multimap.

Examples

m <- cpp_unordered_map(4:6, seq.int(1, by = 0.5, length.out = 3L))
m
# [6,2] [5,1.5] [4,1]

insert(m, seq.int(100, by = 0.1, length.out = 3L), 14:16)
m
# [16,100.2] [15,100.1] [14,100] [6,2] [5,1.5] [4,1]

print(m, n = 3)
# [16,100.2] [15,100.1] [14,100]

m <- cpp_unordered_map(c("world", "hello", "there"), 4:6)
m
# ["there",6] ["hello",5] ["world",4]

erase(m, "there")
m
# ["hello",5] ["world",4]


[Package cppcontainers version 1.0.0 Index]