Learn R Programming

cppcontainers (version 1.0.4)

cpp_multiset: Create multiset

Description

Create a multiset. Multisets are containers of sorted, non-unique elements.

Usage

cpp_multiset(x)

Value

Returns a CppMultiset object referencing a multiset in C++.

Arguments

x

An integer, numeric, character, or logical vector.

Details

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

C++ multiset 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.

See Also

cpp_set, cpp_unordered_set, cpp_unordered_multiset.

Examples

Run this code
s <- cpp_multiset(c(6:9, 6L))
s
# 6 6 7 8 9

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

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

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

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

Run the code above in your browser using DataLab