Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
PackedList Class Reference

A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width> template parameter. More...

Inheritance diagram for PackedList:
Inheritance graph
[legend]
Collaboration diagram for PackedList:
Collaboration graph
[legend]

Classes

struct  hasher
 
class  reference
 

Public Types

typedef unsigned int block_type
 
typedef unsigned int const_reference
 

Public Member Functions

constexpr PackedList () noexcept
 
 PackedList (const label numElem)
 
 PackedList (const label numElem, const unsigned int val)
 
 PackedList (Istream &is)
 
 PackedList (const PackedList< Width > &list)
 
 PackedList (PackedList< Width > &&list)
 
 PackedList (const PackedList< Width > &list, const labelUList &addr)
 
template<class Addr >
 PackedList (const PackedList< Width > &list, const IndirectListBase< label, Addr > &addr)
 
 PackedList (const PackedList< Width > &list, const labelRange &range)
 
 PackedList (const labelUList &values)
 
template<class Addr >
 PackedList (const IndirectListBase< label, Addr > &values)
 
autoPtr< PackedList< Width > > clone () const
 
void checkIndex (const label i) const
 
label size () const noexcept
 
bool empty () const noexcept
 
label capacity () const noexcept
 
bool uniform () const
 
bool equal (const PackedList< Width > &other) const
 
unsigned int get (const label i) const
 
bool set (const label i, unsigned int val=~0u)
 
bool unset (const label i)
 
labelList values () const
 
template<class IntType = unsigned int>
List< IntType > unpack () const
 
template<class IntType = unsigned int>
List< IntType > unpack (const labelRange &range) const
 
template<class IntType = unsigned int>
List< IntType > unpack (const labelUList &locations) const
 
void fill (const unsigned int val)
 
bool trim (label minpos=-1)
 
void reset ()
 
void setCapacity (const label numElem)
 
void resize (const label numElem, const unsigned int val=0u)
 
void resize_nocopy (const label numElem)
 
void reserve (const label numElem)
 
void clear ()
 
void clearStorage ()
 
void shrink ()
 
void swap (PackedList< Width > &rhs)
 
void transfer (PackedList< Width > &rhs)
 
label nBlocks () const
 
const List< unsigned int > & storage () const
 
List< unsigned int > & storage ()
 
const unsigned int * cdata () const noexcept
 
unsigned int * data () noexcept
 
const char * cdata_bytes () const noexcept
 
char * data_bytes () noexcept
 
std::streamsize size_bytes () const noexcept
 
std::streamsize byteSize () const noexcept
 
OstreamprintBits (Ostream &os, bool debugOutput=false) const
 
IstreamreadList (Istream &is)
 
OstreamwriteList (Ostream &os, const label shortLen=0) const
 
void writeEntry (const word &keyword, Ostream &os) const
 
PackedList< Width > & append (const unsigned int val)
 
unsigned int remove ()
 
unsigned int operator[] (const label i) const
 
reference operator[] (const label i)
 
void operator= (const PackedList< Width > &lst)
 
void operator= (PackedList< Width > &&lst)
 
void operator= (const unsigned int val)
 
InfoProxy< PackedList< Width > > info () const
 
void assign (const unsigned int val)
 
void assign (const PackedList< Width > &rhs)
 
void setSize (const label n, unsigned int val=0u)
 
template<unsigned Width>
 PackedList (const PackedList< Width > &list, const labelUList &addr)
 
template<unsigned Width>
 PackedList (const PackedList< Width > &list, const labelRange &range)
 
template<class IntType >
Foam::List< IntType > unpack () const
 
template<class IntType >
Foam::List< IntType > unpack (const labelRange &range) const
 
template<class IntType >
Foam::List< IntType > unpack (const labelUList &locations) const
 
template<unsigned Width>
constexpr PackedList () noexcept
 
template<unsigned Width>
 PackedList (const label numElem)
 
template<unsigned Width>
 PackedList (const label numElem, const unsigned int val)
 
template<unsigned Width>
 PackedList (Istream &is)
 
template<unsigned Width>
 PackedList (const PackedList< Width > &list)
 
template<unsigned Width>
 PackedList (PackedList< Width > &&list)
 
template<unsigned Width>
 PackedList (const labelUList &values)
 

Static Public Member Functions

static constexpr label num_blocks (label numElem) noexcept
 
static constexpr block_type mask_lower (unsigned elementOffset)
 

Static Public Attributes

static constexpr unsigned bits_per_block = (std::numeric_limits<block_type>::digits)
 
static constexpr unsigned element_width = (Width)
 
static constexpr unsigned elem_per_block = (bits_per_block / Width)
 
static constexpr block_type max_value = ((1u << Width) - 1)
 

Protected Types

typedef List< block_typeblock_container
 

Protected Member Functions

void setPair (Istream &is)
 
void writeEntry (Ostream &os) const
 
void clear_trailing_bits ()
 
void copyAssign (const PackedList< Width > &rhs)
 
unsigned int repeated_value (unsigned val)
 
unsigned int readValue (Istream &is)
 
void setPair (Istream &is)
 

Static Protected Member Functions

static unsigned int repeated_value (unsigned val)
 
static unsigned int readValue (Istream &is)
 

Protected Attributes

block_container blocks_
 
label size_
 

Friends

Ostreamoperator (Ostream &os, const InfoProxy< PackedList< Width >> &info)
 
Istreamoperator>> (Istream &is, PackedList< Width > &list)
 

Detailed Description

A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width> template parameter.

Resizing is similar to DynamicList so that clear() and resize() affect the addressed size, but not the allocated size. The reserve() and setCapacity() methods can be used to influence the allocation.

Note
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 a reference to an existing value. When accessing out-of-range elements, some caution is required to ensure that the const version of the [] operator is actually being called. The get() method is functionally identical the the '[]' operator, but is always const access.

The set() and unset() methods return a bool if the value changed.

With const access, the get() method and 'operator[]' are identical. With non-const access, the 'operator[]' may be marginally slower get().

The set() method may be marginally faster than using the 'operator[]' supports auto-vivification and also returns a bool if the value changed, which can be useful for branching on changed values.

list.set(5, 4);
changed = list.set(5, 8);
if (changed) ...

In a const context, reading an out-of-range element returns zero without affecting the list size. For example,

list.resize(4);
Info<< list.get(10) << "\n"; // print zero, but doesn't adjust list
list.set(8); // auto-vivify

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.

Note
Iterators for this class have been intentionally removed, for performance reasons.
See also
Foam::BitOps Foam::DynamicList
Source files

Definition at line 104 of file PackedList.H.

Member Typedef Documentation

◆ block_type

typedef unsigned int block_type

Definition at line 132 of file PackedList.H.

◆ block_container

typedef List<block_type> block_container
protected

Definition at line 177 of file PackedList.H.

◆ const_reference

typedef unsigned int const_reference

Definition at line 224 of file PackedList.H.

Constructor & Destructor Documentation

◆ PackedList() [1/20]

constexpr PackedList ( )
inlineconstexprnoexcept

◆ PackedList() [2/20]

PackedList ( const label  numElem)
inlineexplicit

◆ PackedList() [3/20]

PackedList ( const label  numElem,
const unsigned int  val 
)
inline

◆ PackedList() [4/20]

PackedList ( Istream is)
inline

◆ PackedList() [5/20]

PackedList ( const PackedList< Width > &  list)
inline

◆ PackedList() [6/20]

PackedList ( PackedList< Width > &&  list)
inline

◆ PackedList() [7/20]

PackedList ( const PackedList< Width > &  list,
const labelUList addr 
)

◆ PackedList() [8/20]

PackedList ( const PackedList< Width > &  list,
const IndirectListBase< label, Addr > &  addr 
)

Definition at line 47 of file PackedList.C.

◆ PackedList() [9/20]

PackedList ( const PackedList< Width > &  list,
const labelRange range 
)

◆ PackedList() [10/20]

PackedList ( const labelUList values)
inlineexplicit

◆ PackedList() [11/20]

PackedList ( const IndirectListBase< label, Addr > &  values)
inlineexplicit

Definition at line 252 of file PackedListI.H.

◆ PackedList() [12/20]

PackedList ( const PackedList< Width > &  list,
const labelUList addr 
)

Definition at line 28 of file PackedList.C.

◆ PackedList() [13/20]

PackedList ( const PackedList< Width > &  list,
const labelRange range 
)

Definition at line 65 of file PackedList.C.

◆ PackedList() [14/20]

constexpr PackedList ( )
inlineconstexprnoexcept

Definition at line 170 of file PackedListI.H.

◆ PackedList() [15/20]

PackedList ( const label  numElem)
inline

Definition at line 178 of file PackedListI.H.

◆ PackedList() [16/20]

PackedList ( const label  numElem,
const unsigned int  val 
)
inline

Definition at line 187 of file PackedListI.H.

◆ PackedList() [17/20]

PackedList ( Istream is)
inline

Definition at line 203 of file PackedListI.H.

◆ PackedList() [18/20]

PackedList ( const PackedList< Width > &  list)
inline

Definition at line 213 of file PackedListI.H.

◆ PackedList() [19/20]

PackedList ( PackedList< Width > &&  list)
inline

Definition at line 221 of file PackedListI.H.

◆ PackedList() [20/20]

PackedList ( const labelUList values)
inline

Definition at line 231 of file PackedListI.H.

Member Function Documentation

◆ num_blocks()

static constexpr label num_blocks ( label  numElem)
inlinestaticconstexprnoexcept

◆ mask_lower()

static constexpr block_type mask_lower ( unsigned  elementOffset)
inlinestaticconstexpr

Definition at line 166 of file PackedList.H.

Referenced by PackedList< 2 >::resize().

Here is the caller graph for this function:

◆ repeated_value() [1/2]

unsigned int repeated_value ( unsigned  val)
inlinestaticprotected

Definition at line 27 of file PackedListI.H.

Referenced by PackedList< 2 >::fill(), and PackedList< 2 >::resize().

Here is the caller graph for this function:

◆ readValue() [1/2]

unsigned int readValue ( Istream is)
inlinestaticprotected

Definition at line 34 of file PackedListI.H.

Referenced by PackedList< 2 >::readList().

Here is the caller graph for this function:

◆ setPair() [1/2]

void setPair ( Istream is)
inlineprotected

Definition at line 51 of file PackedListI.H.

Referenced by PackedList< 2 >::readList().

Here is the caller graph for this function:

◆ writeEntry() [1/2]

void writeEntry ( Ostream os) const
protected

Definition at line 27 of file PackedListIO.C.

◆ clear_trailing_bits()

void clear_trailing_bits ( )
inlineprotected

Definition at line 76 of file PackedListI.H.

Referenced by PackedList< 2 >::fill(), PackedList< 2 >::resize(), and PackedList< 2 >::setCapacity().

Here is the caller graph for this function:

◆ copyAssign()

void copyAssign ( const PackedList< Width > &  rhs)
inlineprotected

Definition at line 135 of file PackedListI.H.

◆ clone()

Foam::autoPtr< Foam::PackedList< Width > > clone ( ) const
inline

Definition at line 274 of file PackedListI.H.

◆ checkIndex()

void checkIndex ( const label  i) const
inline

Definition at line 352 of file PackedListI.H.

Referenced by PackedList< 2 >::operator[]().

Here is the caller graph for this function:

◆ size()

Foam::label size ( ) const
inlinenoexcept

◆ empty()

bool empty ( ) const
inlinenoexcept

Definition at line 377 of file PackedListI.H.

Referenced by bitSet::andEq(), ensightMesh::correct(), PackedList< 2 >::fill(), bitSet::minusEq(), bitSet::orEq(), and bitSet::xorEq().

Here is the caller graph for this function:

◆ capacity()

Foam::label capacity ( ) const
inlinenoexcept

Definition at line 384 of file PackedListI.H.

Referenced by Foam::operator<<().

Here is the caller graph for this function:

◆ uniform()

bool uniform ( ) const

Definition at line 86 of file PackedList.C.

Referenced by PackedList< 2 >::writeList().

Here is the caller graph for this function:

◆ equal()

bool equal ( const PackedList< Width > &  other) const

Definition at line 145 of file PackedList.C.

Referenced by Foam::operator!=(), and Foam::operator==().

Here is the caller graph for this function:

◆ get()

unsigned int get ( const label  i) const
inline

◆ set()

bool set ( const label  i,
unsigned int  val = ~0u 
)
inline

Definition at line 646 of file PackedListI.H.

Referenced by PackedList::reference::operator=(), PackedList< 2 >::readList(), syncTools::syncFaceList(), and fileMonitor::updateStates().

Here is the caller graph for this function:

◆ unset()

bool unset ( const label  i)
inline

Definition at line 677 of file PackedListI.H.

◆ values()

Foam::labelList values ( ) const

Definition at line 168 of file PackedList.C.

◆ unpack() [1/6]

List<IntType> unpack ( ) const

◆ unpack() [2/6]

List<IntType> unpack ( const labelRange range) const

◆ unpack() [3/6]

List<IntType> unpack ( const labelUList locations) const

◆ fill()

void fill ( const unsigned int  val)
inline

Definition at line 721 of file PackedListI.H.

Referenced by PackedList< 2 >::assign(), and PackedList< 2 >::operator=().

Here is the caller graph for this function:

◆ trim()

bool trim ( label  minpos = -1)
inline

Definition at line 90 of file PackedListI.H.

◆ reset()

void reset ( )
inline

◆ setCapacity()

void setCapacity ( const label  numElem)
inline

Definition at line 464 of file PackedListI.H.

◆ resize()

void resize ( const label  numElem,
const unsigned int  val = 0u 
)
inline

◆ resize_nocopy()

void resize_nocopy ( const label  numElem)
inline

Definition at line 392 of file PackedListI.H.

◆ reserve()

void reserve ( const label  numElem)
inline

Definition at line 479 of file PackedListI.H.

Referenced by PackedList< 2 >::append(), and PackedList< 2 >::resize().

Here is the caller graph for this function:

◆ clear()

void clear ( )
inline

Definition at line 505 of file PackedListI.H.

Referenced by dynamicRefineFvMesh::calculateProtectedCells(), and PackedList< 2 >::readList().

Here is the caller graph for this function:

◆ clearStorage()

void clearStorage ( )
inline

◆ shrink()

void shrink ( )
inline

Definition at line 521 of file PackedListI.H.

◆ swap()

void swap ( PackedList< Width > &  rhs)
inline

Definition at line 596 of file PackedListI.H.

Referenced by bitSet::swap().

Here is the caller graph for this function:

◆ transfer()

void transfer ( PackedList< Width > &  rhs)
inline

Definition at line 609 of file PackedListI.H.

Referenced by bitSet::transfer().

Here is the caller graph for this function:

◆ nBlocks()

Foam::label nBlocks ( ) const
inline

Definition at line 547 of file PackedListI.H.

◆ storage() [1/2]

const Foam::List< unsigned int > & storage ( ) const
inline

Definition at line 540 of file PackedListI.H.

Referenced by fileMonitor::updateStates().

Here is the caller graph for this function:

◆ storage() [2/2]

Foam::List< unsigned int > & storage ( )
inline

Definition at line 533 of file PackedListI.H.

◆ cdata()

const unsigned int * cdata ( ) const
inlinenoexcept

Definition at line 554 of file PackedListI.H.

Referenced by PackedList::hasher::operator()().

Here is the caller graph for this function:

◆ data()

unsigned int * data ( )
inlinenoexcept

Definition at line 561 of file PackedListI.H.

◆ cdata_bytes()

const char * cdata_bytes ( ) const
inlinenoexcept

Definition at line 568 of file PackedListI.H.

Referenced by syncTools::syncFaceList(), and PackedList< 2 >::writeList().

Here is the caller graph for this function:

◆ data_bytes()

char * data_bytes ( )
inlinenoexcept

Definition at line 575 of file PackedListI.H.

Referenced by PackedList< 2 >::readList(), and syncTools::syncFaceList().

Here is the caller graph for this function:

◆ size_bytes()

std::streamsize size_bytes ( ) const
inlinenoexcept

◆ byteSize()

std::streamsize byteSize ( ) const
inlinenoexcept

Definition at line 589 of file PackedListI.H.

◆ printBits()

Foam::Ostream & printBits ( Ostream os,
bool  debugOutput = false 
) const

Definition at line 37 of file PackedListIO.C.

◆ readList()

Foam::Istream & readList ( Istream is)

Definition at line 57 of file PackedListIO.C.

◆ writeList()

Foam::Ostream & writeList ( Ostream os,
const label  shortLen = 0 
) const

Definition at line 172 of file PackedListIO.C.

Referenced by Foam::operator<<().

Here is the caller graph for this function:

◆ writeEntry() [2/2]

void writeEntry ( const word keyword,
Ostream os 
) const

Definition at line 237 of file PackedListIO.C.

◆ append()

Foam::PackedList< Width > & append ( const unsigned int  val)
inline

Definition at line 690 of file PackedListI.H.

Referenced by PackedList< 2 >::readList().

Here is the caller graph for this function:

◆ remove()

unsigned int remove ( )
inline

Definition at line 702 of file PackedListI.H.

◆ operator[]() [1/2]

unsigned int operator[] ( const label  i) const
inline

Definition at line 748 of file PackedListI.H.

◆ operator[]() [2/2]

Foam::PackedList< Width >::reference operator[] ( const label  i)
inline

Definition at line 756 of file PackedListI.H.

◆ operator=() [1/3]

void operator= ( const PackedList< Width > &  lst)
inline

Referenced by bitSet::operator=().

Here is the caller graph for this function:

◆ operator=() [2/3]

void operator= ( PackedList< Width > &&  lst)
inline

◆ operator=() [3/3]

void operator= ( const unsigned int  val)
inline

Definition at line 780 of file PackedListI.H.

◆ info()

InfoProxy<PackedList<Width> > info ( ) const
inline

Definition at line 507 of file PackedList.H.

◆ assign() [1/2]

void assign ( const unsigned int  val)
inline

Definition at line 547 of file PackedList.H.

◆ assign() [2/2]

void assign ( const PackedList< Width > &  rhs)
inline

Definition at line 551 of file PackedList.H.

◆ setSize()

void setSize ( const label  n,
unsigned int  val = 0u 
)
inline

Definition at line 554 of file PackedList.H.

Referenced by distributedTriSurfaceMesh::getVolumeType(), meshRefinement::markOutsideFaces(), and tetDecomposer::setRefinement().

Here is the caller graph for this function:

◆ unpack() [4/6]

Foam::List<IntType> unpack ( ) const

Definition at line 177 of file PackedList.C.

◆ unpack() [5/6]

Foam::List<IntType> unpack ( const labelRange range) const

Definition at line 229 of file PackedList.C.

◆ unpack() [6/6]

Foam::List<IntType> unpack ( const labelUList locations) const

Definition at line 263 of file PackedList.C.

◆ repeated_value() [2/2]

unsigned int repeated_value ( unsigned  val)
inlineprotected

Definition at line 149 of file PackedListI.H.

◆ readValue() [2/2]

unsigned int readValue ( Istream is)
inlineprotected

Definition at line 154 of file PackedListI.H.

◆ setPair() [2/2]

void setPair ( Istream is)
inlineprotected

Definition at line 159 of file PackedListI.H.

Friends And Related Function Documentation

◆ operator

Ostream& operator ( Ostream os,
const InfoProxy< PackedList< Width >> &  info 
)
friend

◆ operator>>

Istream& operator>> ( Istream is,
PackedList< Width > &  list 
)
friend

Member Data Documentation

◆ bits_per_block

constexpr unsigned bits_per_block = (std::numeric_limits<block_type>::digits)
staticconstexpr

Definition at line 137 of file PackedList.H.

Referenced by PackedList< 2 >::mask_lower().

◆ element_width

constexpr unsigned element_width = (Width)
staticconstexpr

Definition at line 140 of file PackedList.H.

◆ elem_per_block

constexpr unsigned elem_per_block = (bits_per_block / Width)
staticconstexpr

◆ max_value

constexpr block_type max_value = ((1u << Width) - 1)
staticconstexpr

Definition at line 148 of file PackedList.H.

Referenced by PackedList::reference::get(), and PackedList::reference::set().

◆ blocks_

block_container blocks_
protected

◆ size_

label size_
protected

The documentation for this class was generated from the following files:
Foam::Info
messageStream Info