Foam::BitOps Namespace Reference

Various bit-wise operations and adaptor methods for containers that are somewhat similar to bitSet (eg, boolList, labelHashSet). More...

Classes

struct  bitInfo
 An (unsigned) integral type adapter, for output of bit values. More...
 

Functions

unsigned int count (const UList< bool > &bools, const bool val=true)
 Count number of 'true' entries. More...
 
bool all (const UList< bool > &bools)
 True if all entries are 'true' or if the set is empty. More...
 
bool any (const UList< bool > &bools)
 True if any entries are 'true'. More...
 
bool none (const UList< bool > &bools)
 True if no entries are 'true'. More...
 
void set (List< bool > &bools, const labelUList &locations)
 Set the listed locations (assign 'true'). More...
 
void set (List< bool > &bools, const labelRange &range)
 Set the specified range 'on' in a boolList. More...
 
void set (labelHashSet &hashset, const labelRange &range)
 Set the specified range in a labelHashSet. More...
 
void set (bitSet &bitset, const labelRange &range)
 Forward to bitSet::set(labelRange) More...
 
void unset (List< bool > &bools, const labelUList &locations)
 Unset the listed locations (assign 'false'). More...
 
void unset (List< bool > &bools, const labelRange &range)
 Unset the specified range 'on' in a boolList. More...
 
void unset (labelHashSet &hashset, const labelRange &range)
 Unset the specified range in a labelHashSet. More...
 
void unset (bitSet &bitset, const labelRange &range)
 Forward to bitSet::unset(labelRange) More...
 
List< boolselect (const label n, const labelUList &locations)
 
List< boolselect (const labelUList &locations)
 
List< label > toc (const UList< bool > &bools)
 Return the (sorted) values corresponding to 'true' entries. More...
 
List< label > sortedToc (const UList< bool > &bools)
 Return the (sorted) values corresponding to 'true' entries. More...
 
template<class UIntType >
unsigned int bit_count (UIntType x)
 Count arbitrary number of bits (of an integral type) More...
 
template<>
unsigned int bit_count (uint32_t x)
 Count bits in a 32-bit value (Hamming weight method) More...
 
template<>
unsigned int bit_count (uint64_t x)
 Count bits in a 64-bit value (Hamming weight method) More...
 
template<class UIntType , unsigned BitWidth>
UIntType repeat_value (unsigned val)
 Repeat a value of the given BitWidth into the destination output type. More...
 
template<class UIntType >
Ostreamprint (Ostream &os, UIntType value, char off='0', char on='1')
 Print 0/1 bits in the (unsigned) integral type. More...
 

Detailed Description

Various bit-wise operations and adaptor methods for containers that are somewhat similar to bitSet (eg, boolList, labelHashSet).

The population count uses the Hamming weight (http://en.wikipedia.org/wiki/Hamming_weight).

Function Documentation

◆ count()

unsigned int count ( const UList< bool > &  bools,
const bool  val = true 
)
inline

Count number of 'true' entries.

Parameters
valcan be set to false to count the number of false values instead For compatibility with bitSet::count()

Definition at line 78 of file BitOps.H.

Referenced by geometric::add(), decompositionMethod::decompose(), and toc().

Here is the caller graph for this function:

◆ all()

bool all ( const UList< bool > &  bools)
inline

True if all entries are 'true' or if the set is empty.

For compatibility with bitSet::all()

Definition at line 85 of file BitOps.H.

Referenced by decompositionMethod::decompose().

Here is the caller graph for this function:

◆ any()

bool any ( const UList< bool > &  bools)
inline

True if any entries are 'true'.

For compatibility with bitSet::any()

Definition at line 92 of file BitOps.H.

◆ none()

bool none ( const UList< bool > &  bools)
inline

True if no entries are 'true'.

For compatibility with bitSet::none()

Definition at line 99 of file BitOps.H.

◆ set() [1/4]

void set ( List< bool > &  bools,
const labelUList locations 
)

Set the listed locations (assign 'true').

Does auto-vivify for non-existent entries.

For compatibility with bitSet::set(labelUList)

Definition at line 38 of file BitOps.C.

References UList< T >::begin(), UList< T >::end(), max(), List< T >::resize(), and UList< T >::size().

Here is the call graph for this function:

◆ set() [2/4]

void set ( List< bool > &  bools,
const labelRange range 
)

Set the specified range 'on' in a boolList.

For compatibility with bitSet::set(labelRange)

Definition at line 60 of file BitOps.C.

References labelRange::adjust(), labelRange::after(), IntRange< IntType >::empty(), range, List< T >::resize(), List< T >::set(), and UList< T >::size().

Here is the call graph for this function:

◆ set() [3/4]

void set ( labelHashSet hashset,
const labelRange range 
)

Set the specified range in a labelHashSet.

For compatibility with bitSet::set(labelRange)

Definition at line 89 of file BitOps.C.

References labelRange::adjust(), range, and HashSet< Key, Hash >::set().

Here is the call graph for this function:

◆ set() [4/4]

void set ( bitSet bitset,
const labelRange range 
)

Forward to bitSet::set(labelRange)

Definition at line 101 of file BitOps.C.

References range, and bitSet::set().

Here is the call graph for this function:

◆ unset() [1/4]

void unset ( List< bool > &  bools,
const labelUList locations 
)

Unset the listed locations (assign 'false').

No auto-vivify non-existent entries.

For compatibility with bitSet::set(labelUList)

Definition at line 107 of file BitOps.C.

References UList< T >::unset().

Here is the call graph for this function:

◆ unset() [2/4]

void unset ( List< bool > &  bools,
const labelRange range 
)

Unset the specified range 'on' in a boolList.

For compatibility with bitSet::unset(labelRange)

Definition at line 117 of file BitOps.C.

References range, and UList< T >::unset().

Here is the call graph for this function:

◆ unset() [3/4]

void unset ( labelHashSet hashset,
const labelRange range 
)

Unset the specified range in a labelHashSet.

For compatibility with bitSet::unset(labelRange)

Definition at line 126 of file BitOps.C.

References range, and HashSet< Key, Hash >::unset().

Here is the call graph for this function:

◆ unset() [4/4]

void unset ( bitSet bitset,
const labelRange range 
)

Forward to bitSet::unset(labelRange)

Definition at line 135 of file BitOps.C.

References range, and bitSet::unset().

Here is the call graph for this function:

◆ select() [1/2]

Foam::List< bool > select ( const label  n,
const labelUList locations 
)

Construct a selection list of bools (all false) with the given pre-size, subsequently add specified locations as true, auto-vivify entries if needed.

Similar to bitSet construction from locations

Returns
a List of bools

Definition at line 141 of file BitOps.C.

References n.

◆ select() [2/2]

Foam::List< bool > select ( const labelUList locations)

Construct an auto-sized selection list of bools (all false), and populate the specified locations as true.

Similar to bitSet construction from locations

Returns
a List of bools

Definition at line 155 of file BitOps.C.

◆ toc()

Foam::List< Foam::label > toc ( const UList< bool > &  bools)

Return the (sorted) values corresponding to 'true' entries.

Similar to bitSet::toc()

Returns
a List of labels

Definition at line 166 of file BitOps.C.

References b, count(), and UList< T >::size().

Here is the call graph for this function:

◆ sortedToc()

Foam::List< Foam::label > sortedToc ( const UList< bool > &  bools)

Return the (sorted) values corresponding to 'true' entries.

Similar to bitSet::sortedToc() and labelHashSet::sortedToc()

Returns
a List of labels

Definition at line 203 of file BitOps.C.

◆ bit_count() [1/3]

unsigned int bit_count ( UIntType  x)
inline

Count arbitrary number of bits (of an integral type)

Definition at line 171 of file BitOps.H.

References n, and x.

Referenced by bitSet::count().

Here is the caller graph for this function:

◆ bit_count() [2/3]

unsigned int bit_count ( uint32_t  x)
inline

Count bits in a 32-bit value (Hamming weight method)

Definition at line 183 of file BitOps.H.

References x.

◆ bit_count() [3/3]

unsigned int bit_count ( uint64_t  x)
inline

Count bits in a 64-bit value (Hamming weight method)

Definition at line 194 of file BitOps.H.

References x.

◆ repeat_value()

UIntType repeat_value ( unsigned  val)
inline

Repeat a value of the given BitWidth into the destination output type.

Note
when BitWidth is 1, it is better to do directly.
(val ? ~0u : 0u)

Definition at line 211 of file BitOps.H.

◆ print()

Ostream & print ( Ostream os,
UIntType  value,
char  off = '0',
char  on = '1' 
)
inline

Print 0/1 bits in the (unsigned) integral type.

Definition at line 240 of file BitOps.H.

References STLCore::BINARY, and os().

Referenced by Foam::operator<<().

Here is the call graph for this function:
Here is the caller graph for this function: