Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


cppcontainers (version 1.0.4)

cpp_unordered_set: Create unordered set

Description

Create an unordered set. Unordered sets are containers of unique, unsorted elements.

Usage

cpp_unordered_set(x)

Value

Returns a CppUnorderedSet object referencing an unordered_set in C++.

Arguments

x

An integer, numeric, character, or logical vector.

Details

Unordered sets are associative containers. They do not provide random access through an index. I.e. s[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 sets in some applications faster than sets. I.e., elements in unordered sets are unique, but not sorted.

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

See Also

cpp_set, cpp_multiset, cpp_unordered_multiset.

Examples

Run this code
s <- cpp_unordered_set(6:10)
s
# 10 9 8 7 6 

insert(s, 4:7)
s
# 5 4 10 9 8 7 6

print(s, n = 3L)
# 5 4 10 

s <- cpp_unordered_set(c("world", "hello", "there"))
s
# "there" "hello" "world" 

erase(s, "there")
s
# "hello" "world"

Run the code above in your browser using DataLab