Polymake Template Library (PTL): pm::Bitset Class Reference

Container class for dense sets of integers. More...

Inheritance diagram for pm::Bitset:
Collaboration diagram for pm::Bitset:

Public Types

typedef int element_type
 element types
 
typedef operations::cmp element_comparator
 functor type for comparing elements
 
typedef GenericSet generic_type
 generic type
 
typedef Generic< Bitset >::top_type top_type
 top type
 

Public Member Functions

 Bitset ()
 An empty set, with minimal preallocated storage.
 
 Bitset (int n, bool full=false)
 An empty set with preallocated storage for elements 0..n-1. More...
 
 Bitset (const GenericSet< Bitset > &s)
 Copy of a disguised Bitset object.
 
template<typename TSet >
 Bitset (const GenericSet< TSet, int > &s)
 Copy of an abstract set of integers.
 
template<typename TSet , typename E2 , typename Comparator2 , typename = typename std::enable_if<std::is_convertible<E2, int>::value>::type>
 Bitset (const GenericSet< TSet, E2, Comparator2 > &s)
 Copy of an abstract set with element conversion.
 
 Bitset (gmp_randstate_t rnd, unsigned long bits)
 Fill with a prescribed number of random bits.
 
Bitsetoperator= (const GenericSet< Bitset > &s)
 Assign elements from a disguised Bitset object.
 
void reserve (int n)
 Reserve storage for n elements.
 
void clear ()
 Make the set empty.
 
template<typename TSet >
Bitsetoperator= (const GenericSet< TSet, int > &s)
 Assign elements from an abstract set of integers.
 
int size () const noexcept
 
Bitsetoperator+= (int i)
 
Bitsetoperator-= (int i)
 
Bitsetoperator-= (const Bitset &s)
 difference
 
Bitsetoperator*= (int i)
 intersection
 

Detailed Description

Container class for dense sets of integers.

A special class optimized for representation of a constrained range of non-negative integer numbers. Its implementation is based on the GMP (mpz_t), see http://www.swox.com/gmp/ 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 through the element upper bound) is expected to be rather 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.

Constructor & Destructor Documentation

pm::Bitset::Bitset ( int  n,
bool  full = false 
)
inlineexplicit

An empty set with preallocated storage for elements 0..n-1.

It can dynamically grow beyond this limit if needed; to avoid performance penalties, however, you should specify here the highest element you really expect to occur.

Parameters
n
fullSet this to 1 if the set contains all elements from 0 to n-1, defaults to 0.

Member Function Documentation

Bitset& pm::Bitset::operator+= ( int  i)
inline

Insert an element. This is the quickest way to manipulate single elements.

Bitset& pm::Bitset::operator-= ( int  i)
inline

Remove an element if it existed. This is the quickest way to manipulate single elements.

int pm::Bitset::size ( ) const
inlinenoexcept

Count the elements. CAUTION: depending on the hardware, can take O(n) time!


The documentation for this class was generated from the following file:
  • lib/core/include/Bitset.h