This is a data structure that compactly stores the presence of
integers in some finite set (max_size
), and can
efficiently perform set operations (union, intersection, complement, symmetric
difference, set difference).
WARNING: All operations are in-place so please use $copy
if you would like to perform an operation without destroying your current bitset.
This class is defined as a named list for performance reasons, but for most
intents and purposes it behaves just like an R6 class.
Methods
Method new()
create a bitset.
Arguments
size
the size of the bitset.
from
pointer to an existing IterableBitset to use; if NULL
make empty bitset, otherwise copy existing bitset.
Method insert()
insert into the bitset.
Arguments
v
an integer vector of elements to insert.
remove from the bitset.
Arguments
v
an integer vector of elements (not indices) to remove.
Method clear()
clear the bitset.
Method size()
get the number of elements in the set.
Method or()
to "bitwise or" or union two bitsets.
Arguments
other
the other bitset.
Method and()
to "bitwise and" or intersect two bitsets.
Arguments
other
the other bitset.
Method not()
to "bitwise not" or complement a bitset.
Arguments
inplace
whether to overwrite the current bitset, default = TRUE
to "bitwise xor" get the symmetric difference of two bitset
(keep elements in either bitset but not in their intersection).
Arguments
other
the other bitset.
Method set_difference()
Take the set difference of this bitset with another
(keep elements of this bitset which are not in other
)
Arguments
other
the other bitset.
sample a bitset.
Arguments
rate
the success probability for keeping each element, can be
a single value for all elements or a vector of unique
probabilities for keeping each element.
choose k random items in the bitset.
Arguments
k
the number of items in the bitset to keep. The selection of
these k items from N total items in the bitset is random, and
k should be chosen such that \(0 \le k \le N\).
Method copy()
returns a copy of the bitset.
In cases where a destination bitset already exists, it may be more
performant to use the copy_from
method instead.
Method copy_from()
overwrite the value of the bitset from another bitset.
This is similar to calling other$copy()
, but can be more
efficient by reusing the resources of the existing bitset.
Arguments
other
the other bitset.
Method to_vector()
return an integer vector of the elements stored in this bitset.