A dynamically allocatable list of packed unsigned integers. More...
Data Structures | |
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, initializes 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 (const Xfer< PackedList< nBits > > &) | |
Construct by transferring the parameter contents. 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... | |
Xfer< 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... | |
Xfer< PackedList< nBits > > | xfer () |
Transfer contents to the Xfer container. More... | |
Istream & | read (Istream &) |
Clear list and read from stream. More... | |
Ostream & | write (Ostream &, const bool indexedOutput=false) const |
Write, optionally with indexedOutput. More... | |
void | writeEntry (Ostream &) const |
Write as a dictionary entry. More... | |
void | writeEntry (const word &keyword, Ostream &) const |
Write as a dictionary entry with keyword. 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... | |
PackedList< nBits > & | operator= (const unsigned int val) |
Assignment of all entries to the given value. Takes linear time. More... | |
PackedList< nBits > & | operator= (const PackedList< nBits > &) |
Assignment operator. More... | |
PackedList< nBits > & | operator= (const labelUList &) |
Assignment operator. More... | |
PackedList< nBits > & | 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... | |
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 specialization) More... | |
Private Member Functions | |
StaticAssert (nBits &&nBits<=(sizeof(StorageType)<< 2)) | |
nBits must be positive (non-zero) and fit within the storage. More... | |
Private Attributes | |
label | size_ |
Number of nBits entries. 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.
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 assigment 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 specialization 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 117 of file PackedList.H.
|
protected |
Definition at line 153 of file PackedList.H.
|
protected |
Definition at line 154 of file PackedList.H.
|
inline |
Null constructor.
Definition at line 169 of file PackedListI.H.
|
inlineexplicit |
Construct with given size, initializes list to 0.
Definition at line 178 of file PackedListI.H.
|
inline |
Construct with given size and value for all elements.
|
inline |
Construct from Istream.
|
inline |
Copy constructor.
|
inline |
Construct by transferring the parameter contents.
|
inlineexplicit |
Construct from a list of labels.
|
inlineexplicit |
Construct from an indirect list of labels.
|
inlinestaticprotected |
Calculate the list length when packed.
Referenced by PackedBoolList::bitorPrepare(), and PackedBoolList::unset().
|
inlinestaticprotected |
Read a list entry (allows for specialization)
Referenced by PackedList< 2 >::read().
|
inlineprotected |
Read an index/value pair and set accordingly.
For bool specialization, read a single index value
Referenced by PackedList< 2 >::read().
|
private |
nBits must be positive (non-zero) and fit within the storage.
For efficiency, however, require packing at least 2 items otherwise it is more efficient to use a normal list. Thus max nBits is 1/2 of the base storage size. For simplicity, assume 8-bit bytes in the assert.
|
inlinestatic |
The max. number of bits that can be templated.
Might someday be useful for a template assert.
Definition at line 32 of file PackedListI.H.
Referenced by main().
|
inlinestatic |
The max. value for an entry, which simultaneously the bit-mask.
eg, ((1 << 2) - 1) yields 0b0011
Definition at line 39 of file PackedListI.H.
Referenced by PackedList::iteratorBase::get(), main(), PackedList< 2 >::operator=(), reportInfo(), PackedList< 2 >::resize(), and PackedList::iteratorBase::set().
|
inlinestatic |
The number of entries per packed storage element.
Definition at line 46 of file PackedListI.H.
Referenced by PackedList< 2 >::capacity(), PackedList::iteratorBase::get(), PackedList< 2 >::operator=(), reportInfo(), PackedList< 2 >::resize(), PackedList::iteratorBase::set(), and PackedList< 2 >::setCapacity().
|
inlinestatic |
Masking for all bits below the offset.
Definition at line 53 of file PackedListI.H.
Referenced by PackedList< 2 >::operator=(), reportInfo(), PackedList< 2 >::resize(), and PackedList< 2 >::setCapacity().
|
inline |
Clone.
Definition at line 261 of file PackedListI.H.
|
inline |
The number of elements that can be stored before reallocating.
Definition at line 834 of file PackedListI.H.
|
inline |
Number of entries.
Definition at line 714 of file PackedListI.H.
Referenced by PackedBoolList::bitorPrepare(), meshRefinement::calculateEdgeWeights(), primitiveMesh::checkClosedBoundary(), meshRefinement::gAverage(), main(), PackedBoolList::subset(), syncTools::syncEdgeList(), syncTools::syncFaceList(), syncTools::syncPointList(), meshRefinement::weightedSum(), and PackedList< 2 >::write().
|
inline |
Return true if the list is empty (ie, size() is zero).
Definition at line 721 of file PackedListI.H.
Referenced by dynamicRefineFvMesh::selectRefineCells().
|
inline |
Get value at index I.
Never auto-vivify entries.
Definition at line 964 of file PackedListI.H.
Referenced by autoLayerDriver::averageNeighbours(), isoSurfaceCell::calcCutType(), isoSurfaceCell::calcSnappedCc(), isoSurfaceCell::calcSnappedPoint(), isoSurface::calcSnappedPoint(), dynamicRefineFvMesh::calculateProtectedCells(), hexRef8::consistentSlowRefinement2(), hexRef8::consistentUnrefinement(), dynamicRefineFvMesh::count(), meshRefinement::countHits(), dynamicRefineFvMesh::dynamicRefineFvMesh(), dynamicRefineFvMesh::extendMarkedCells(), meshRefinement::getChangedFaces(), meshRefinement::intersectedPoints(), main(), meshRefinement::markFacesOnProblemCells(), motionSmootherAlgo::minSmooth(), PackedList::iteratorBase::operator unsigned int(), PackedList::iteratorBase::operator!=(), PackedList::const_iterator::operator()(), PackedList::const_iterator::operator*(), PackedList::iteratorBase::operator==(), NASedgeFormat::read(), STARCDedgeFormat::read(), autoSnapDriver::repatchToSurface(), dynamicRefineFvMesh::selectRefineCells(), dynamicRefineFvMesh::selectUnrefinePoints(), hexRef8::setRefinement(), fieldSmoother::smoothNormals(), autoSnapDriver::smoothPatchDisplacement(), testPackedList(), and meshRefinement::updateIntersections().
|
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 995 of file PackedListI.H.
Referenced by main(), PackedList::iteratorBase::operator=(), and testPackedList().
|
inline |
Unset the entry at index I. Return true if value changed.
Never auto-vivify entries.
Definition at line 1016 of file PackedListI.H.
Referenced by main().
|
inline |
Return the underlying packed storage.
Manipulate with utmost caution
Definition at line 919 of file PackedListI.H.
Referenced by PackedBoolList::bitorPrepare(), main(), PackedBoolList::operator^=(), PackedList< 2 >::read(), PackedBoolList::set(), PackedBoolList::subset(), PackedBoolList::unset(), fileMonitor::updateStates(), and PackedList< 2 >::write().
|
inline |
Return the underlying packed storage.
Definition at line 926 of file PackedListI.H.
|
inline |
The list length when packed.
Definition at line 933 of file PackedListI.H.
Referenced by PackedList< 2 >::byteSize(), PackedList< 2 >::operator=(), PackedList< 2 >::packedLength(), PackedList< 2 >::reserve(), PackedList< 2 >::resize(), PackedList< 2 >::setCapacity(), and PackedList< 2 >::shrink().
|
inline |
Return the binary size in number of characters.
used in the underlying storage
Definition at line 940 of file PackedListI.H.
Referenced by PackedList< 2 >::read(), and PackedList< 2 >::write().
unsigned int count | ( | ) | const |
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.
Referenced by autoLayerDriver::addLayers(), polyMeshFilter::filterEdges(), polyMeshFilter::filterFacesLoop(), polyTopoChange::getSetIndices(), main(), NASedgeFormat::read(), STARCDedgeFormat::read(), and dynamicRefineFvMesh::selectUnrefinePoints().
Foam::Xfer< Foam::labelList > values | ( | ) | const |
Return the values as a list of labels.
Definition at line 134 of file PackedList.C.
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 166 of file PackedList.C.
Referenced by main().
Foam::Ostream & printInfo | ( | Ostream & | os, |
const bool | fullOutput = false |
||
) | const |
Print information and bit patterns (with printBits)
Definition at line 235 of file PackedList.C.
Referenced by main().
bool trim | ( | ) |
Trim any trailing zero elements.
Definition at line 74 of file PackedList.C.
Referenced by main(), Foam::operator&(), and Foam::operator^().
void flip | ( | ) |
Invert the bits in the addressable region.
Definition at line 104 of file PackedList.C.
Referenced by main(), and PackedBoolList::operator~().
|
inline |
Clear all bits.
Definition at line 885 of file PackedListI.H.
Referenced by PackedList< 2 >::clear().
|
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 841 of file PackedListI.H.
Referenced by main().
|
inline |
Reset addressable list size, does not shrink the allocated size.
Optionally specify a value for new elements.
Definition at line 729 of file PackedListI.H.
Referenced by main(), PackedList< 2 >::read(), PackedList< 2 >::remove(), PackedList< 2 >::set(), and PackedList< 2 >::setSize().
|
inline |
Alias for resize()
Definition at line 823 of file PackedListI.H.
Referenced by displacementLayeredMotionMotionSolver::calcZoneMask(), meshRefinement::consistentOrientation(), motionSmootherAlgo::getAffectedFacesAndPoints(), meshRefinement::getIntersections(), PatchTools::matchEdges(), and targetVolumeToCell::selectCells().
|
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 863 of file PackedListI.H.
Referenced by PackedList< 2 >::append(), main(), PackedList< 2 >::resize(), and PackedBoolList::subsetIndices().
|
inline |
Clear the list, i.e. set addressable size to zero.
Does not adjust the underlying storage
Definition at line 892 of file PackedListI.H.
Referenced by dynamicRefineFvMesh::calculateProtectedCells(), dynamicRefineFvMesh::dynamicRefineFvMesh(), main(), PackedList< 2 >::read(), and meshRefinement::zonify().
|
inline |
Clear the list and delete storage.
Definition at line 900 of file PackedListI.H.
|
inline |
Shrink the allocated space to what is actually used.
Definition at line 908 of file PackedListI.H.
Referenced by main().
|
inline |
Transfer the contents of the argument list into this list.
and annul the argument list.
Definition at line 947 of file PackedListI.H.
Referenced by PackedBoolList::transfer().
|
inline |
Transfer contents to the Xfer container.
Definition at line 957 of file PackedListI.H.
Foam::Istream & read | ( | Istream & | is | ) |
Clear list and read from stream.
Definition at line 254 of file PackedList.C.
Referenced by main().
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 specialization 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 399 of file PackedList.C.
Referenced by main().
void writeEntry | ( | Ostream & | ) | const |
|
inline |
Append a value at the end of the list.
Definition at line 1032 of file PackedListI.H.
Referenced by main(), and PackedList< 2 >::read().
|
inline |
Remove and return the last element.
Definition at line 1044 of file PackedListI.H.
Referenced by main().
|
inline |
Get value at index I.
Never auto-vivify entries.
|
inline |
Set value at index I.
Returns iterator to perform the actual operation. Does not auto-vivify entries, but will when assigned to.
|
inline |
Assignment of all entries to the given value. Takes linear time.
Definition at line 1070 of file PackedListI.H.
Referenced by PackedBoolList::operator=().
PackedList<nBits>& operator= | ( | const PackedList< nBits > & | ) |
Assignment operator.
PackedList<nBits>& operator= | ( | const labelUList & | ) |
Assignment operator.
PackedList<nBits>& operator= | ( | const UIndirectList< label > & | ) |
Assignment operator.
|
inline |
Iterator set to the beginning of the PackedList.
Definition at line 665 of file PackedListI.H.
Referenced by main().
|
inline |
Iterator set to beyond the end of the PackedList.
Definition at line 689 of file PackedListI.H.
Referenced by main().
|
inline |
const_iterator set to the beginning of the PackedList
Definition at line 681 of file PackedListI.H.
Referenced by PackedList< 2 >::write().
|
inline |
const_iterator set to beyond the end of the PackedList
Definition at line 705 of file PackedListI.H.
Referenced by main(), and PackedList< 2 >::write().
|
inline |
const_iterator set to the beginning of the PackedList
Definition at line 673 of file PackedListI.H.
|
inline |
const_iterator set to beyond the end of the PackedList
Definition at line 697 of file PackedListI.H.
|
inlineprotected |
Definition at line 73 of file PackedListI.H.
|
inlineprotected |
Definition at line 80 of file PackedListI.H.
|
friend |
|
friend |
|
private |
Number of nBits entries.
Definition at line 181 of file PackedList.H.
Referenced by PackedList< 2 >::append(), PackedList< 2 >::cend(), PackedList< 2 >::clear(), PackedList< 2 >::clearStorage(), PackedList< 2 >::empty(), PackedList< 2 >::end(), PackedList< 2 >::get(), PackedList< 2 >::operator=(), PackedList< 2 >::packedLength(), PackedList< 2 >::remove(), PackedList< 2 >::resize(), PackedList< 2 >::set(), PackedList< 2 >::setCapacity(), PackedList< 2 >::size(), PackedList< 2 >::transfer(), and PackedList< 2 >::unset().
Copyright © 2011-2018 OpenFOAM | OPENFOAM® is a registered trademark of OpenCFD Ltd.