cpp_set {cppcontainers}R Documentation

Create set

Description

Create a set. Sets are containers of unique, sorted elements.

Usage

cpp_set(x)

Arguments

x

An integer, numeric, character, or logical vector.

Details

Sets are associative containers. They do not provide random access through an index. I.e., s[2] does not return the second element.

C++ set 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 CppSet object referencing a set in C++.

See Also

cpp_unordered_set, cpp_multiset, cpp_unordered_multiset.

Examples

s <- cpp_set(6:9)
s
# 6 7 8 9

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

print(s, from = 6)
# 6 7 8 9

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

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


[Package cppcontainers version 1.0.0 Index]