Bitset: A Bitset Class

Description Public fields Methods

Description

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.

Public fields

.bitset

a pointer to the underlying IterableBitset.

max_size

the maximum size of the bitset.

Methods

Public methods


Method new()

create a bitset.

Usage
Bitset$new(size, from = NULL)
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.

Usage
Bitset$insert(v)
Arguments
v

an integer vector of elements to insert.


Method remove()

remove from the bitset.

Usage
Bitset$remove(v)
Arguments
v

an integer vector of elements (not indices) to remove.


Method size()

get the number of elements in the set.

Usage
Bitset$size()

Method or()

to "bitwise or" or union two bitsets.

Usage
Bitset$or(other)
Arguments
other

the other bitset.


Method and()

to "bitwise and" or intersect two bitsets.

Usage
Bitset$and(other)
Arguments
other

the other bitset.


Method not()

to "bitwise not" or complement a bitset.

Usage
Bitset$not(inplace)
Arguments
inplace

whether to overwrite the current bitset.


Method xor()

to "bitwise xor" or get the symmetric difference of two bitset (keep elements in either bitset but not in their intersection).

Usage
Bitset$xor(other)
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).

Usage
Bitset$set_difference(other)
Arguments
other

the other bitset.


Method sample()

sample a bitset.

Usage
Bitset$sample(rate)
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.


Method choose()

choose k random items in the bitset

Usage
Bitset$choose(k)
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 ≤ k ≤ N.


Method copy()

returns a copy the bitset.

Usage
Bitset$copy()

Method to_vector()

return an integer vector of the elements stored in this bitset.

Usage
Bitset$to_vector()

Method clone()

The objects of this class are cloneable with this method.

Usage
Bitset$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


individual documentation built on Oct. 25, 2021, 9:09 a.m.