cpp_multiset {cppcontainers} | R Documentation |
Create multiset
Description
Create a multiset. Multisets are containers of sorted, non-unique elements.
Usage
cpp_multiset(x)
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
.
Value
Returns a CppMultiset object referencing a multiset in C++.
See Also
cpp_set, cpp_unordered_set, cpp_unordered_multiset.
Examples
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"