A dynamically allocatable list of packed unsigned integers. More...
#include <OpenFOAM/PackedList.H>
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,
Definition at line 113 of file PackedList.H.
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. | |
PackedList (const label size) | |
Construct with given size, initializes list to 0. | |
PackedList (const label size, const unsigned val) | |
Construct with given size and value for all elements. | |
PackedList (const PackedList< nBits > &) | |
Copy constructor. | |
PackedList (const Xfer< PackedList< nBits > > &) | |
Construct by transferring the parameter contents. | |
PackedList (const UList< label > &) | |
Construct from a list of labels. | |
autoPtr< PackedList< nBits > > | clone () const |
Clone. | |
label | capacity () const |
The number of elements that can be stored before reallocating. | |
label | size () const |
Number of entries. | |
bool | empty () const |
Return true if the list is empty (ie, size() is zero). | |
unsigned int | get (const label) const |
Get value at index I. | |
bool | set (const label, const unsigned int val=~0u) |
Set value at index I. Return true if value changed. | |
bool | unset (const label) |
Unset the entry at index I. Return true if value changed. | |
List< unsigned int > & | storage () |
Return the underlying packed storage. | |
const List< unsigned int > & | storage () const |
Return the underlying packed storage. | |
unsigned int | count () const |
Count number of bits set, O(log(n)) | |
labelList | values () const |
Return the values as a labelList. | |
Ostream & | print (Ostream &) const |
Print values and information. | |
bool | trim () |
Trim any trailing zero elements. | |
void | flip () |
Invert the bits in the addressable region. | |
void | setCapacity (const label) |
Alter the size of the underlying storage. | |
void | resize (const label, const unsigned int &val=0) |
Reset addressable list size, does not shrink the allocated size. | |
void | setSize (const label, const unsigned int &val=0) |
Alias for resize() | |
void | reserve (const label) |
Reserve allocation space for at least this size. | |
void | clear () |
Clear the list, i.e. set addressable size to zero. | |
void | clearStorage () |
Clear the list and delete storage. | |
void | shrink () |
Shrink the allocated space to what is actually used. | |
void | transfer (PackedList< nBits > &) |
Transfer the contents of the argument list into this list. | |
Xfer< PackedList< nBits > > | xfer () |
Transfer contents to the Xfer container. | |
void | append (const unsigned int val) |
Append a value at the end of the list. | |
unsigned int | remove () |
Remove and return the last element. | |
unsigned int | operator[] (const label) const |
Get value at index I. | |
iteratorBase | operator[] (const label) |
Set value at index I. | |
void | operator= (const unsigned int val) |
Assignment of all entries to the given value. Takes linear time. | |
void | operator= (const PackedList< nBits > &) |
Assignment operator. Takes linear time. | |
void | operator= (const UList< label > &) |
Assignment operator. Takes linear time. | |
iterator | begin () |
iterator set to the beginning of the PackedList | |
iterator | end () |
iterator set to beyond the end of the PackedList | |
const_iterator | cbegin () const |
const_iterator set to the beginning of the PackedList | |
const_iterator | cend () const |
const_iterator set to beyond the end of the PackedList | |
const_iterator | begin () const |
const_iterator set to the beginning of the PackedList | |
const_iterator | end () const |
const_iterator set to beyond the end of the PackedList | |
template<> | |
void | operator= (const unsigned int val) |
Static Public Member Functions | |
static unsigned int | max_bits () |
The max. number of bits that can be templated. | |
static unsigned int | max_value () |
The max. value for an entry, which simultaneously the bit-mask. | |
static unsigned int | packing () |
The number of entries per packed storage element. | |
static unsigned int | maskLower (unsigned offset) |
Masking for all bits below the offset. |
Additional Inherited Members | |
![]() | |
typedef SubList< unsigned int > | subList |
Declare type of subList. | |
![]() | |
typedef unsigned int | value_type |
Type of values the UList contains. | |
typedef unsigned int & | reference |
Type that can be used for storing into. | |
typedef const unsigned int & | const_reference |
Type that can be used for storing into. | |
typedef label | difference_type |
The type that can represent the difference between any two. | |
typedef label | size_type |
The type that can represent the size of a UList. | |
typedef unsigned int * | iterator |
Random access iterator for traversing UList. | |
typedef const unsigned int * | const_iterator |
Random access iterator for traversing UList. | |
typedef unsigned int * | reverse_iterator |
Reverse iterator for reverse traversal of UList. | |
typedef const unsigned int * | const_reverse_iterator |
Reverse iterator for reverse traversal of constant UList. | |
![]() | |
List () | |
Null constructor. | |
List (const label) | |
Construct with given size. | |
List (const label, const unsigned int &) | |
Construct with given size and value for all elements. | |
List (const List< unsigned int > &) | |
Copy constructor. | |
List (const Xfer< List< unsigned int > > &) | |
Construct by transferring the parameter contents. | |
List (List< unsigned int > &, bool reUse) | |
Construct as copy or re-use as specified. | |
List (const UList< unsigned int > &, const unallocLabelList &mapAddressing) | |
Construct as subset. | |
List (InputIterator first, InputIterator last) | |
Construct given start and end iterators. | |
List (const FixedList< unsigned int, Size > &) | |
Construct as copy of FixedList<T, Size> | |
List (const PtrList< unsigned int > &) | |
Construct as copy of PtrList<T> | |
List (const SLList< unsigned int > &) | |
Construct as copy of SLList<T> | |
List (const IndirectList< unsigned int > &) | |
Construct as copy of IndirectList<T> | |
List (const UIndirectList< unsigned int > &) | |
Construct as copy of UIndirectList<T> | |
List (const BiIndirectList< unsigned int > &) | |
Construct as copy of BiIndirectList<T> | |
List (Istream &) | |
Construct from Istream. | |
~List () | |
void | resize (const label) |
Reset size of List. | |
void | setSize (const label) |
Reset size of List. | |
void | append (const UList< unsigned int > &) |
Append a List at the end of this list. | |
void | append (const UIndirectList< unsigned int > &) |
Append a UIndirectList at the end of this list. | |
void | transfer (List< unsigned int > &) |
Transfer the contents of the argument List into this list. | |
void | transfer (DynamicList< unsigned int, SizeInc, SizeMult, SizeDiv > &) |
Transfer the contents of the argument List into this list. | |
void | transfer (SortableList< unsigned int > &) |
Transfer the contents of the argument List into this list. | |
unsigned int & | newElmt (const label) |
Return subscript-checked element of UList. | |
void | operator= (const UList< unsigned int > &) |
Assignment from UList operator. Takes linear time. | |
void | operator= (const List< unsigned int > &) |
Assignment operator. Takes linear time. | |
void | operator= (const SLList< unsigned int > &) |
Assignment from SLList operator. Takes linear time. | |
void | operator= (const IndirectList< unsigned int > &) |
Assignment from IndirectList operator. Takes linear time. | |
void | operator= (const UIndirectList< unsigned int > &) |
Assignment from UIndirectList operator. Takes linear time. | |
void | operator= (const BiIndirectList< unsigned int > &) |
Assignment from BiIndirectList operator. Takes linear time. | |
void | operator= (const unsigned int &) |
Assignment of all entries to the given value. | |
void | size (const label) |
Override size to be inconsistent with allocated storage. | |
![]() | |
UList () | |
Null constructor. | |
UList (unsigned int *__restrict__ v, label size) | |
Construct from components. | |
label | fcIndex (const label i) const |
Return the forward circular index, i.e. the next index. | |
label | rcIndex (const label i) const |
Return the reverse circular index, i.e. the previous index. | |
label | byteSize () const |
Return the binary size in number of characters of the UList. | |
const unsigned int * | cdata () const |
Return a const pointer to the first data element,. | |
unsigned int * | data () |
Return a pointer to the first data element,. | |
void | checkStart (const label start) const |
Check start is within valid range (0 ... size-1). | |
void | checkSize (const label size) const |
Check size is within valid range (0 ... size). | |
void | checkIndex (const label i) const |
Check index i is within valid range (0 ... size-1). | |
void | writeEntry (Ostream &) const |
Write the UList as a dictionary entry. | |
void | writeEntry (const word &keyword, Ostream &) const |
Write the UList as a dictionary entry with keyword. | |
void | assign (const UList< unsigned int > &) |
Assign elements to those from UList. | |
operator const Foam::List< unsigned int > & () const | |
Allow cast to a const List<T>&. | |
reverse_iterator | rbegin () |
Return reverse_iterator to begin reverse traversing the UList. | |
const_reverse_iterator | rbegin () const |
Return const_reverse_iterator to begin reverse traversing the UList. | |
reverse_iterator | rend () |
Return reverse_iterator to end reverse traversing the UList. | |
const_reverse_iterator | rend () const |
Return const_reverse_iterator to end reverse traversing the UList. | |
const_reverse_iterator | crbegin () const |
Return const_reverse_iterator to begin reverse traversing the UList. | |
const_reverse_iterator | crend () const |
Return const_reverse_iterator to end reverse traversing the UList. | |
label | max_size () const |
Return size of the largest possible UList. | |
void | swap (UList< unsigned int > &) |
Swap two ULists of the same type in constant time. | |
bool | operator== (const UList< unsigned int > &) const |
Equality operation on ULists of the same type. | |
bool | operator!= (const UList< unsigned int > &) const |
The opposite of the equality operation. Takes linear time. | |
bool | operator< (const UList< unsigned int > &) const |
Compare two ULists lexicographically. Takes linear time. | |
bool | operator> (const UList< unsigned int > &) const |
Compare two ULists lexicographically. Takes linear time. | |
bool | operator<= (const UList< unsigned int > &) const |
Return true if !(a > b). Takes linear time. | |
bool | operator>= (const UList< unsigned int > &) const |
Return true if !(a < b). Takes linear time. | |
![]() | |
static const List< unsigned int > & | null () |
Return a null List. |
|
inline |
Null constructor.
Definition at line 73 of file PackedListI.H.
|
inlineexplicit |
Construct with given size, initializes list to 0.
Definition at line 81 of file PackedListI.H.
PackedList | ( | const label | size, |
const unsigned | val | ||
) |
Construct with given size and value for all elements.
|
inline |
Copy constructor.
Definition at line 89 of file PackedListI.H.
|
inline |
Construct by transferring the parameter contents.
Definition at line 97 of file PackedListI.H.
|
explicit |
|
inlinestatic |
The max. number of bits that can be templated.
Might someday be useful for a template assert.
Definition at line 33 of file PackedListI.H.
|
inlinestatic |
The max. value for an entry, which simultaneously the bit-mask.
eg, ((1 << 2) - 1) yields 0b0011
Definition at line 40 of file PackedListI.H.
Referenced by PackedList< nBits >::iteratorBase::get(), PackedList< nBits >::operator=(), PackedList< nBits >::resize(), and PackedList< nBits >::iteratorBase::set().
|
inlinestatic |
The number of entries per packed storage element.
Definition at line 47 of file PackedListI.H.
Referenced by PackedList< nBits >::capacity(), PackedList< nBits >::iteratorBase::get(), PackedList< nBits >::operator=(), PackedList< nBits >::resize(), and PackedList< nBits >::iteratorBase::set().
|
inlinestatic |
Masking for all bits below the offset.
Definition at line 54 of file PackedListI.H.
Referenced by PackedList< nBits >::resize().
|
inline |
|
inline |
The number of elements that can be stored before reallocating.
Definition at line 642 of file PackedListI.H.
References PackedList< nBits >::packing(), and List< T >::size().
|
inline |
Number of entries.
Reimplemented from List< unsigned int >.
Definition at line 553 of file PackedListI.H.
Referenced by PackedList< nBits >::operator=(), syncTools::syncEdgeList(), syncTools::syncFaceList(), and syncTools::syncPointList().
|
inline |
Return true if the list is empty (ie, size() is zero).
Reimplemented from UList< unsigned int >.
Definition at line 560 of file PackedListI.H.
Referenced by dynamicRefineFvMesh::selectRefineCells().
|
inline |
Get value at index I.
Never auto-vivify entries.
Definition at line 748 of file PackedListI.H.
References Foam::abort(), Foam::FatalError, FatalErrorIn, and PackedList< nBits >::iteratorBase::get().
Referenced by dynamicRefineFvMesh::calculateProtectedCells(), hexRef8::consistentSlowRefinement2(), dynamicRefineFvMesh::count(), meshRefinement::countHits(), dynamicRefineFvMesh::extendMarkedCells(), PackedList< nBits >::iteratorBase::operator==(), dynamicRefineFvMesh::selectRefineCells(), dynamicRefineFvMesh::selectUnrefinePoints(), syncTools::syncEdgeList(), syncTools::syncFaceList(), and syncTools::syncPointList().
|
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 788 of file PackedListI.H.
References Foam::abort(), Foam::FatalError, FatalErrorIn, PackedList< nBits >::resize(), and PackedList< nBits >::iteratorBase::set().
Referenced by triSurfaceMesh::calcBounds(), dynamicRefineFvMesh::calculateProtectedCells(), dynamicRefineFvMesh::dynamicRefineFvMesh(), dynamicRefineFvMesh::extendMarkedCells(), dynamicRefineFvMesh::refine(), dynamicRefineFvMesh::selectRefineCandidates(), syncTools::syncEdgeList(), syncTools::syncFaceList(), syncTools::syncPointList(), dynamicRefineFvMesh::unrefine(), and triSurface::writeStats().
|
inline |
Unset the entry at index I. Return true if value changed.
Never auto-vivify entries.
Definition at line 813 of file PackedListI.H.
References PackedList< nBits >::iteratorBase::set().
|
inline |
Return the underlying packed storage.
Definition at line 715 of file PackedListI.H.
|
inline |
Return the underlying packed storage.
Definition at line 723 of file PackedListI.H.
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 79 of file PackedList.C.
References COUNT_PACKEDBITS.
Foam::labelList values | ( | ) | const |
Foam::Ostream & print | ( | Ostream & | os | ) | const |
bool trim | ( | ) |
Trim any trailing zero elements.
Definition at line 113 of file PackedList.C.
void flip | ( | ) |
Invert the bits in the addressable region.
Definition at line 165 of file PackedList.C.
|
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 649 of file PackedListI.H.
References List< T >::setSize().
|
inline |
Reset addressable list size, does not shrink the allocated size.
Optionally specify a value for new elements.
Reimplemented from List< unsigned int >.
Definition at line 568 of file PackedListI.H.
References PackedList< nBits >::maskLower(), PackedList< nBits >::max_value(), PackedList< nBits >::operator=(), UList< T >::operator[](), PackedList< nBits >::packing(), and PackedList< nBits >::reserve().
Referenced by PackedList< nBits >::remove(), PackedList< nBits >::set(), and PackedList< nBits >::setSize().
|
inline |
Alias for resize()
Reimplemented from List< unsigned int >.
Definition at line 631 of file PackedListI.H.
References PackedList< nBits >::resize().
|
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 663 of file PackedListI.H.
References Foam::max(), List< T >::setSize(), and List< T >::size().
Referenced by PackedList< nBits >::append(), and PackedList< nBits >::resize().
|
inline |
Clear the list, i.e. set addressable size to zero.
Does not adjust the underlying storage
Reimplemented from List< unsigned int >.
Definition at line 687 of file PackedListI.H.
Referenced by dynamicRefineFvMesh::calculateProtectedCells(), and dynamicRefineFvMesh::dynamicRefineFvMesh().
|
inline |
Clear the list and delete storage.
Definition at line 694 of file PackedListI.H.
References List< T >::clear().
|
inline |
Shrink the allocated space to what is actually used.
Definition at line 702 of file PackedListI.H.
References List< T >::setSize(), and List< T >::size().
|
inline |
Transfer the contents of the argument list into this list.
and annul the argument list.
Definition at line 730 of file PackedListI.H.
References List< T >::transfer().
|
inline |
Transfer contents to the Xfer container.
Reimplemented from List< unsigned int >.
Definition at line 741 of file PackedListI.H.
References Foam::xferMove().
|
inline |
Append a value at the end of the list.
Definition at line 826 of file PackedListI.H.
References PackedList< nBits >::reserve(), and PackedList< nBits >::iteratorBase::set().
|
inline |
Remove and return the last element.
Definition at line 837 of file PackedListI.H.
References Foam::abort(), Foam::FatalError, FatalErrorIn, PackedList< nBits >::iteratorBase::get(), and PackedList< nBits >::resize().
|
inline |
Get value at index I.
Never auto-vivify entries.
Reimplemented from UList< unsigned int >.
Definition at line 772 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.
Reimplemented from UList< unsigned int >.
Definition at line 857 of file PackedListI.H.
|
inline |
Assignment of all entries to the given value. Takes linear time.
Definition at line 882 of file PackedListI.H.
References PackedList< nBits >::max_value(), List< T >::operator=(), and PackedList< nBits >::packing().
Referenced by PackedList< nBits >::operator=(), and PackedList< nBits >::resize().
void operator= | ( | const PackedList< nBits > & | lst | ) |
Assignment operator. Takes linear time.
Definition at line 267 of file PackedList.C.
References PackedList< nBits >::size().
Assignment operator. Takes linear time.
Definition at line 275 of file PackedList.C.
References forAll, and UList< T >::size().
|
inline |
iterator set to the beginning of the PackedList
Reimplemented from UList< unsigned int >.
Definition at line 504 of file PackedListI.H.
|
inline |
iterator set to beyond the end of the PackedList
Reimplemented from UList< unsigned int >.
Definition at line 528 of file PackedListI.H.
|
inline |
const_iterator set to the beginning of the PackedList
Reimplemented from UList< unsigned int >.
Definition at line 520 of file PackedListI.H.
|
inline |
const_iterator set to beyond the end of the PackedList
Reimplemented from UList< unsigned int >.
Definition at line 544 of file PackedListI.H.
|
inline |
const_iterator set to the beginning of the PackedList
Reimplemented from UList< unsigned int >.
Definition at line 512 of file PackedListI.H.
|
inline |
const_iterator set to beyond the end of the PackedList
Reimplemented from UList< unsigned int >.
Definition at line 536 of file PackedListI.H.
|
inline |
Definition at line 867 of file PackedListI.H.
References PackedList< nBits >::operator=().