pm::Bitset Class Reference

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

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

List of all members.


Public Member Functions

 Bitset ()
 An empty set, without preallocated storage.
 Bitset (int n, bool full=false)
 An empty set with preallocated storage for elements 0..n-1.
 Bitset (const GenericSet< Bitset > &s)
 Copy of a disguised Bitset object.
template<typename _Set>
 Bitset (const GenericSet< _Set, int > &s)
 Copy of an abstract set of integers.
template<typename _Set, typename E2, typename Comparator2>
 Bitset (const GenericSet< _Set, E2, Comparator2 > &s)
 Copy of an abstract set with element conversion.
Bitset & operator= (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 _Set>
Bitset & operator= (const GenericSet< _Set, int > &s)
 Assign elements from an abstract set of integers.
int size () const
Bitset & operator+= (int i)
Bitset & operator-= (int i)
Bitset & operator-= (const Bitset &s)
 difference
Bitset & operator*= (const Bitset &s)
 intersection

Friends

Bitset operator| (const Bitset &s1, const Bitset &s2)
 alias for operator+
Bitset operator & (const Bitset &s1, const Bitset &s2)
 alias for operator*

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.

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.


Constructor & Destructor Documentation

pm::Bitset::Bitset ( int  n,
bool  full = false 
) [inline, explicit]

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 
full Set this to 1 if the set contains all elements from 0 to n-1, defaults to 0.


Member Function Documentation

int pm::Bitset::size (  )  const [inline]

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

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.


The documentation for this class was generated from the following file:
  • include/core/polymake/Bitset.h
Generated on Wed Mar 30 23:31:45 2011 for Polymake Template Library (PTL) by doxygen 1.5.6