A special class optimized for representation of a constrained range of non-negative integer numbers.
Its implementation is based on the GMP integer numbers.
You should consider to use it instead of the more general Set<int> if all these criteria hold:
— the element range stays constant during the lifetime of the set
— the element range is small (magnitude of tens), or the fill grade (number of elements divided
thru the element upper bound) is expected to be considerably high (>= 0.5)
— the number of random access operations (testing/addition/removal of single elements) prevails
significantly over the number of sequential visits via iterators
Note that unlike std::bitset, the element range is not hard encoded in the Bitset
object, but can be dynamically changed any time.
Bitset is one of the few top-level classes in the Polymake Template Library that does not
make use of reference counted smart pointers. It's difficult to say why. You should keep this in mind
if you want to copy or return Bitset objects by value.
Create an empty set, anticipating it will eventually contain elements in the range [0..n].
This is just an optimization hint for the internal memory housekeeping,
and by no means a constraint for the elements to be added later to the set.
Create a set, initialize the elements from a data sequence.
The only purpose of the dummy argument end_sensitive is to signal that the first argument src
has to be treated as an end-sensitive iterator.
A template constructor with a single argument would shadow all other constructors away!
Swap the contents of two sets in a most efficient way.
void Bitset::clear();
Make the set empty.
void Bitset::reserve (int n);
Give a hint that elements from range [0..n] are expected to be added later.
Additional memory is allocated if needed. As in the constructor case, it is only a hint, not a restriction.
Bitset implements the Reversible Container STL interface.
Futhermore, all set-theoretic operations and
input/output operators are applicable to Bitset objects.
Some of them have specializations optimized for Bitset, as far as GMP supports them,
but this should be transparent to the user.
For the sake of interchangeability with Set<int> following methods are defined:
Bitset::iterator Bitset::insert (int x);
Bitset::iterator Bitset::insert (const Bitset::iterator&, int x);
The same as Bitset::operator+= (int) .
The optional iterator argument is introduced solely for the sake of compatibility with other set classes and is ignored.
Return an iterator pointing to the added element.
The same as Bitset::operator+= (int) .
x need not even to be in fact the greatest/least element, since the operation works directly with
the corresponding bit of the internal representation.