A dynamically allocatable list of packed unsigned integers. More...
Classes | |
class | const_iterator |
The const_iterator for PackedList. More... | |
class | iterator |
The iterator class used for PackedList. More... | |
class | iteratorBase |
The iterator base for PackedList. More... | |
Public Member Functions | |
PackedList () | |
Null constructor. More... | |
PackedList (const label size) | |
Construct with given size, initialises list to 0. More... | |
PackedList (const label size, const unsigned val) | |
Construct with given size and value for all elements. More... | |
PackedList (Istream &) | |
Construct from Istream. More... | |
PackedList (const PackedList< nBits > &) | |
Copy constructor. More... | |
PackedList (PackedList< nBits > &&) | |
Move constructor. More... | |
PackedList (const labelUList &) | |
Construct from a list of labels. More... | |
PackedList (const UIndirectList< label > &) | |
Construct from an indirect list of labels. More... | |
autoPtr< PackedList< nBits > > | clone () const |
Clone. More... | |
label | capacity () const |
The number of elements that can be stored before reallocating. More... | |
label | size () const |
Number of entries. More... | |
bool | empty () const |
Return true if the list is empty (ie, size() is zero). More... | |
unsigned int | get (const label) const |
Get value at index I. More... | |
bool | set (const label, const unsigned int val=~0u) |
Set value at index I. Return true if value changed. More... | |
bool | unset (const label) |
Unset the entry at index I. Return true if value changed. More... | |
List< unsigned int > & | storage () |
Return the underlying packed storage. More... | |
const List< unsigned int > & | storage () const |
Return the underlying packed storage. More... | |
label | packedLength () const |
The list length when packed. More... | |
std::streamsize | byteSize () const |
Return the binary size in number of characters. More... | |
unsigned int | count () const |
Count number of bits set, O(log(n)) More... | |
labelList | values () const |
Return the values as a list of labels. More... | |
Ostream & | printBits (Ostream &, const bool fullOutput=false) const |
Print bit patterns, optionally output unused elements. More... | |
Ostream & | printInfo (Ostream &, const bool fullOutput=false) const |
Print information and bit patterns (with printBits) More... | |
bool | trim () |
Trim any trailing zero elements. More... | |
void | flip () |
Invert the bits in the addressable region. More... | |
void | reset () |
Clear all bits. More... | |
void | setCapacity (const label) |
Alter the size of the underlying storage. More... | |
void | resize (const label, const unsigned int &val=0u) |
Reset addressable list size, does not shrink the allocated size. More... | |
void | setSize (const label, const unsigned int &val=0u) |
Alias for resize() More... | |
void | reserve (const label) |
Reserve allocation space for at least this size. More... | |
void | clear () |
Clear the list, i.e. set addressable size to zero. More... | |
void | clearStorage () |
Clear the list and delete storage. More... | |
void | shrink () |
Shrink the allocated space to what is actually used. More... | |
void | transfer (PackedList< nBits > &) |
Transfer the contents of the argument list into this list. More... | |
Istream & | read (Istream &) |
Clear list and read from stream. More... | |
Ostream & | write (Ostream &, const bool indexedOutput=false) const |
Write, optionally with indexedOutput. More... | |
PackedList< nBits > & | append (const unsigned int val) |
Append a value at the end of the list. More... | |
unsigned int | remove () |
Remove and return the last element. More... | |
unsigned int | operator[] (const label) const |
Get value at index I. More... | |
iteratorBase | operator[] (const label) |
Set value at index I. More... | |
void | operator= (const unsigned int val) |
Assignment of all entries to the given value. Takes linear time. More... | |
void | operator= (const PackedList< nBits > &) |
Assignment operator. More... | |
void | operator= (PackedList< nBits > &&) |
Move assignment operator. More... | |
void | operator= (const labelUList &) |
Assignment operator. More... | |
void | operator= (const UIndirectList< label > &) |
Assignment operator. More... | |
iterator | begin () |
Iterator set to the beginning of the PackedList. More... | |
iterator | end () |
Iterator set to beyond the end of the PackedList. More... | |
const_iterator | cbegin () const |
const_iterator set to the beginning of the PackedList More... | |
const_iterator | cend () const |
const_iterator set to beyond the end of the PackedList More... | |
const_iterator | begin () const |
const_iterator set to the beginning of the PackedList More... | |
const_iterator | end () const |
const_iterator set to beyond the end of the PackedList More... | |
Public Member Functions inherited from PackedListCore | |
PackedListCore () | |
Construct null. More... | |
ClassName ("PackedList") | |
Define template name and debug. More... | |
Static Public Member Functions | |
static unsigned int | max_bits () |
The max. number of bits that can be templated. More... | |
static unsigned int | max_value () |
The max. value for an entry, which simultaneously the bit-mask. More... | |
static unsigned int | packing () |
The number of entries per packed storage element. More... | |
static unsigned int | maskLower (unsigned offset) |
Masking for all bits below the offset. More... | |
Protected Types | |
typedef unsigned int | StorageType |
typedef List< StorageType > | StorageList |
Protected Member Functions | |
void | setPair (Istream &) |
Read an index/value pair and set accordingly. More... | |
unsigned int | readValue (Istream &is) |
void | setPair (Istream &is) |
Static Protected Member Functions | |
static label | packedLength (const label) |
Calculate the list length when packed. More... | |
static unsigned int | readValue (Istream &) |
Read a list entry (allows for specialisation) More... | |
Friends | |
Istream & | operator>> (Istream &, PackedList< nBits > &) |
Ostream & | operator (Ostream &, const PackedList< nBits > &) |
A dynamically allocatable list of packed unsigned integers.
The list resizing is similar to DynamicList, thus the methods clear() and setSize() behave like their DynamicList counterparts and the methods reserve() and setCapacity() can be used to influence the allocation.
The number of bits per item is specified by the template parameter nBits.
In a const context, the '[]' operator simply returns the stored value, with out-of-range elements returned as zero. In a non-const context, the '[]' operator returns an iteratorBase, which might not have a valid reference for out-of-range elements. The iteratorBase class handles the assignment of new values.
Using the iteratorBase as a proxy allows assignment of values between list elements. Thus the following bit of code works as expected:
Using get() or the '[]' operator are similarly fast. Looping and reading via an iterator is approx. 15% slower, but can be more flexible.
Using the set() operator (and the '[]' operator) are marginally slower (approx. 5%) than using an iterator, but the set() method has the advantage of also returning a bool if the value changed. This can be useful for branching on changed values.
The lazy evaluation used means that reading an out-of-range element returns zero, but does not affect the list size. Even in a non-const context, only the assignment itself causes the element to be created. For example,
Also note that all unused internal storage elements are guaranteed to always be bit-wise zero. This property must not be violated by any inheriting classes.
In addition to the normal output format, PackedList also supports a compact ASCII format that may be convenient for user input in some situations. The general format is a group of index/value pairs:
{ (index1 value1) (index2 value2) (index3 value3) }
The bool specialisation just uses the indices corresponding to non-zero entries instead of a index/value pair:
{ index1 index2 index3 }
In both cases, the supplied indices can be randomly ordered.
Definition at line 149 of file PackedList.H.
|
protected |
Definition at line 156 of file PackedList.H.
|
protected |
Definition at line 157 of file PackedList.H.
|
inline |
Null constructor.
Definition at line 168 of file PackedListI.H.
|
inlineexplicit |
Construct with given size, initialises list to 0.
Definition at line 177 of file PackedListI.H.
|
inline |
Construct with given size and value for all elements.
|
inline |
Construct from Istream.
Definition at line 204 of file PackedListI.H.
|
inline |
Copy constructor.
Definition at line 215 of file PackedListI.H.
|
inline |
Move constructor.
Definition at line 224 of file PackedListI.H.
|
inlineexplicit |
Construct from a list of labels.
Definition at line 231 of file PackedListI.H.
|
inlineexplicit |
Construct from an indirect list of labels.
Definition at line 245 of file PackedListI.H.
References forAll.
|
inlinestaticprotected |
Calculate the list length when packed.
Definition at line 62 of file PackedListI.H.
Referenced by PackedBoolList::unset().
|
inlinestaticprotected |
Read a list entry (allows for specialisation)
Definition at line 103 of file PackedListI.H.
References Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, and Foam::readLabel().
Referenced by PackedList< nBits >::read().
|
inlineprotected |
Read an index/value pair and set accordingly.
For bool specialisation, read a single index value
Definition at line 120 of file PackedListI.H.
References IOstream::check(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Istream::readBegin(), Istream::readEnd(), and Foam::readLabel().
|
inlinestatic |
The max. number of bits that can be templated.
Might someday be useful for a template assert.
Definition at line 31 of file PackedListI.H.
Referenced by PackedList< nBits >::printBits().
|
inlinestatic |
The max. value for an entry, which simultaneously the bit-mask.
eg, ((1 << 2) - 1) yields 0b0011
Definition at line 38 of file PackedListI.H.
Referenced by PackedList< nBits >::printInfo().
|
inlinestatic |
The number of entries per packed storage element.
Definition at line 45 of file PackedListI.H.
Referenced by PackedList< nBits >::printBits(), PackedList< nBits >::iteratorBase::printInfo(), and PackedList< nBits >::printInfo().
|
inlinestatic |
Masking for all bits below the offset.
Definition at line 52 of file PackedListI.H.
References Foam::offset().
Referenced by PackedList< nBits >::printBits().
|
inline |
Clone.
Definition at line 260 of file PackedListI.H.
|
inline |
The number of elements that can be stored before reallocating.
Definition at line 831 of file PackedListI.H.
Referenced by PackedList< nBits >::printInfo().
|
inline |
Number of entries.
Definition at line 711 of file PackedListI.H.
Referenced by meshRefinement::calculateEdgeWeights(), meshRefinement::gAverage(), PackedList< nBits >::operator=(), PackedList< 1 >::operator=(), PackedBoolList::subset(), syncTools::syncEdgeList(), syncTools::syncFaceList(), syncTools::syncPointList(), and meshRefinement::weightedSum().
|
inline |
Return true if the list is empty (ie, size() is zero).
Definition at line 718 of file PackedListI.H.
Referenced by cellsToCells::srcCoupled(), patchToPatch::srcCoupled(), cellsToCells::tgtCoupled(), and patchToPatch::tgtCoupled().
|
inline |
Get value at index I.
Never auto-vivify entries.
Definition at line 954 of file PackedListI.H.
References PackedList< nBits >::iteratorBase::get().
Referenced by PackedList< 1 >::clear(), hexRef8::consistentSlowRefinement2(), hexRef8::consistentUnrefinement(), meshRefinement::countHits(), treeDataFace::getVolumeType(), meshRefinement::intersectedPoints(), PackedList< nBits >::iteratorBase::operator=(), NASedgeFormat::read(), STARCDedgeFormat::read(), refiner::refiner(), snappySnapDriver::repatchToSurface(), hexRef8::setRefinement(), PackedList< 1 >::transfer(), and refiner::update().
|
inline |
Set value at index I. Return true if value changed.
Does auto-vivify for non-existent entries. Default value set is the max_value.
Definition at line 984 of file PackedListI.H.
References resize(), and PackedList< nBits >::iteratorBase::set().
Referenced by PackedList< 1 >::capacity(), and PackedList< nBits >::operator=().
|
inline |
Unset the entry at index I. Return true if value changed.
Never auto-vivify entries.
Definition at line 1006 of file PackedListI.H.
References PackedList< nBits >::iteratorBase::set().
|
inline |
Return the underlying packed storage.
Manipulate with utmost caution
Definition at line 916 of file PackedListI.H.
Referenced by PackedBoolList::operator^=(), PackedBoolList::set(), PackedBoolList::subset(), PackedBoolList::unset(), and fileMonitor::updateStates().
|
inline |
Return the underlying packed storage.
Definition at line 923 of file PackedListI.H.
|
inline |
The list length when packed.
Definition at line 930 of file PackedListI.H.
Referenced by PackedList< nBits >::printBits(), and PackedList< nBits >::printInfo().
|
inline |
Return the binary size in number of characters.
used in the underlying storage
Definition at line 937 of file PackedListI.H.
unsigned int count |
Count number of bits set, O(log(n))
Uses the Hamming weight (population count) method http://en.wikipedia.org/wiki/Hamming_weight
Definition at line 55 of file PackedList.C.
References Foam::constant::universal::c, and COUNT_PACKEDBITS.
Referenced by polyMeshFilter::filterEdges(), PackedList< nBits >::printInfo(), NASedgeFormat::read(), and STARCDedgeFormat::read().
Foam::labelList values |
Return the values as a list of labels.
Definition at line 134 of file PackedList.C.
References forAll.
Foam::Ostream & printBits | ( | Ostream & | os, |
const bool | fullOutput = false |
||
) | const |
Print bit patterns, optionally output unused elements.
addressable bits: on: '1', off: '-'
non-addressable bits: on: '!', off: '.'
Definition at line 165 of file PackedList.C.
References PackedList< nBits >::maskLower(), PackedList< nBits >::max_bits(), UList< T >::operator[](), PackedList< nBits >::packedLength(), PackedList< nBits >::packing(), and List< T >::size().
Referenced by PackedList< nBits >::printInfo().
Foam::Ostream & printInfo | ( | Ostream & | os, |
const bool | fullOutput = false |
||
) | const |
Print information and bit patterns (with printBits)
Definition at line 234 of file PackedList.C.
References PackedList< nBits >::capacity(), PackedList< nBits >::count(), PackedList< nBits >::max_value(), Foam::nl, PackedList< nBits >::packedLength(), PackedList< nBits >::packing(), PackedList< nBits >::printBits(), and List< T >::size().
bool trim |
Trim any trailing zero elements.
Definition at line 74 of file PackedList.C.
Referenced by Foam::operator&(), and Foam::operator^().
void flip |
Invert the bits in the addressable region.
Definition at line 104 of file PackedList.C.
Referenced by PackedBoolList::operator~().
|
inline |
Clear all bits.
Definition at line 882 of file PackedListI.H.
|
inline |
Alter the size of the underlying storage.
The addressed size will be truncated if needed to fit, but will remain otherwise untouched.
Definition at line 838 of file PackedListI.H.
References setSize().
Referenced by PackedList< nBits >::operator=(), and polyTopoChange::polyTopoChange().
|
inline |
Reset addressable list size, does not shrink the allocated size.
Optionally specify a value for new elements.
Definition at line 725 of file PackedListI.H.
Referenced by PackedList< nBits >::iteratorBase::operator=(), and PackedList< nBits >::read().
|
inline |
Alias for resize()
Definition at line 819 of file PackedListI.H.
References resize().
Referenced by PatchTools::matchEdges().
|
inline |
Reserve allocation space for at least this size.
Never shrinks the allocated size. The list size is adjusted as per DynamicList with SizeInc=0, SizeMult=2, SizeDiv=1
Definition at line 860 of file PackedListI.H.
References Foam::max(), and setSize().
Referenced by PackedBoolList::subsetIndices().
|
inline |
Clear the list, i.e. set addressable size to zero.
Does not adjust the underlying storage
Definition at line 889 of file PackedListI.H.
Referenced by PackedList< nBits >::read(), and refiner::refiner().
|
inline |
Clear the list and delete storage.
Definition at line 897 of file PackedListI.H.
References clear().
|
inline |
Shrink the allocated space to what is actually used.
Definition at line 905 of file PackedListI.H.
References setSize().
|
inline |
Transfer the contents of the argument list into this list.
and annul the argument list.
Definition at line 944 of file PackedListI.H.
Referenced by PackedList< nBits >::operator=(), and PackedBoolList::transfer().
Foam::Istream & read | ( | Istream & | is | ) |
Clear list and read from stream.
Definition at line 254 of file PackedList.C.
References IOstream::ASCII, token::BEGIN_LIST, PackedList< nBits >::clear(), IOstream::fatalCheck(), IOstream::format(), token::isLabel(), token::labelToken(), Istream::readBeginList(), PackedList< nBits >::readValue(), and PackedList< nBits >::resize().
Foam::Ostream & write | ( | Ostream & | os, |
const bool | indexedOutput = false |
||
) | const |
Write, optionally with indexedOutput.
The indexed output may be convenient in some situations. The general format is a group of index/value pairs:
{ (index1 value1) (index2 value2) (index3 value3) }
The bool specialisation just uses the indices corresponding to non-zero entries instead of a index/value pair:
{ index1 index2 index3 }
Note the indexed output is only supported for ASCII streams.
Definition at line 398 of file PackedList.C.
|
inline |
Append a value at the end of the list.
Definition at line 1022 of file PackedListI.H.
References PackedList< nBits >::iteratorBase::set().
|
inline |
Remove and return the last element.
Definition at line 1034 of file PackedListI.H.
References Foam::abort(), Foam::FatalError, FatalErrorInFunction, PackedList< nBits >::iteratorBase::get(), and resize().
Get value at index I.
Never auto-vivify entries.
Definition at line 969 of file PackedListI.H.
References PackedList< nBits >::iteratorBase::get().
|
inline |
Set value at index I.
Returns iterator to perform the actual operation. Does not auto-vivify entries, but will when assigned to.
Definition at line 1052 of file PackedListI.H.
|
inline |
Assignment of all entries to the given value. Takes linear time.
Definition at line 1059 of file PackedListI.H.
Referenced by PackedList< 1 >::max_bits(), and PackedBoolList::operator=().
void operator= | ( | const PackedList< nBits > & | lst | ) |
Assignment operator.
Definition at line 496 of file PackedList.C.
References List< T >::operator=(), and PackedList< nBits >::size().
void operator= | ( | PackedList< nBits > && | lst | ) |
Move assignment operator.
Definition at line 504 of file PackedList.C.
References PackedList< nBits >::transfer().
void operator= | ( | const labelUList & | lst | ) |
Assignment operator.
Definition at line 511 of file PackedList.C.
References forAll, PackedList< nBits >::set(), PackedList< nBits >::setCapacity(), and UList< T >::size().
void operator= | ( | const UIndirectList< label > & | lst | ) |
Assignment operator.
Definition at line 524 of file PackedList.C.
References forAll, PackedList< nBits >::set(), PackedList< nBits >::setCapacity(), and UIndirectList< T >::size().
|
inline |
Iterator set to the beginning of the PackedList.
Definition at line 662 of file PackedListI.H.
|
inline |
Iterator set to beyond the end of the PackedList.
Definition at line 686 of file PackedListI.H.
|
inline |
const_iterator set to the beginning of the PackedList
Definition at line 678 of file PackedListI.H.
Referenced by PackedList< 1 >::operator=().
|
inline |
const_iterator set to beyond the end of the PackedList
Definition at line 702 of file PackedListI.H.
Referenced by PackedList< 1 >::operator=().
|
inline |
const_iterator set to the beginning of the PackedList
Definition at line 670 of file PackedListI.H.
|
inline |
const_iterator set to beyond the end of the PackedList
Definition at line 694 of file PackedListI.H.
|
inlineprotected |
Definition at line 72 of file PackedListI.H.
References Foam::readBool().
|
inlineprotected |
Definition at line 79 of file PackedListI.H.
References Foam::readLabel().
|
friend |
|
friend |