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

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

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

Public Types

using element_type = E
 element types
 
using element_comparator = Comparator
 functor type for comparing elements
 
using generic_type = GenericSet
 generic type
 
using top_type = typename Generic< Top >::top_type
 top type
 

Public Member Functions

 Bitset ()
 An empty set, with minimal preallocated storage.
 
 Bitset (Int n, const bool full=false)
 An empty set with preallocated storage for elements 0..n-1. More...
 
 Bitset (const mpz_t &b)
 Copy the value from a third party.
 
 Bitset (mpz_t &&b) noexcept
 
 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 = std::enable_if_t<std::is_convertible<E2, Int>::value>>
 Bitset (const GenericSet< TSet, E2, Comparator2 > &s)
 Copy of an abstract set with element conversion.
 
 Bitset (gmp_randstate_t rnd, Int 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 resize (Int n)
 Synonym for reserve, for compatibility with other set classes.
 
void clear ()
 Make the set empty.
 
template<typename Set2 >
std::enable_if_t<!std::is_same< Set2, Bitset >::value, Bitset & > operator= (const GenericSet< Set2, Int, element_comparator > &s)
 Assign elements from an abstract set of integers.
 
Int size () const noexcept
 
Bitsetoperator+= (Int i)
 
Bitsetoperator-= (Int i)
 
Bitsetoperator*= (Int i)
 intersection
 
bool operator== (const GenericSet< Set2, E, Comparator > &s) const
 comparison
 
bool operator< (const GenericSet< Set2, E, Comparator > &s) const
 lexicographical comparison
 

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

◆ Bitset() [1/2]

pm::Bitset::Bitset ( Int  n,
const 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.

◆ Bitset() [2/2]

pm::Bitset::Bitset ( mpz_t &&  b)
inlineexplicitnoexcept

Steal the value from a third party The source must be re-initialized if it's going to be used afterwards

Member Function Documentation

◆ operator+=()

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

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

◆ operator-=()

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

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

◆ size()

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