93 #ifndef Foam_PackedList_H 94 #define Foam_PackedList_H 102 #include <type_traits> 112 template<
unsigned W
idth>
115 template<
unsigned W
idth>
116 Ostream& operator<<(Ostream& os, const PackedList<Width>& list);
118 template<
unsigned W
idth>
119 Ostream& operator<<(Ostream& os, const InfoProxy<PackedList<Width>>& info);
143 template<
unsigned W
idth>
159 = (std::numeric_limits<block_type>::digits);
215 "Width must be > 0 and minimum of two items per data block" 264 inline explicit
PackedList(const label numElem);
268 inline
PackedList(const label numElem, const
unsigned int val);
333 inline
unsigned int get(const label i) const;
338 inline
bool set(const label i,
unsigned int val = ~0u);
345 inline
bool unset(const label i);
352 template<class IntType =
unsigned int>
353 List<IntType>
unpack() const;
357 template<class IntType =
unsigned int>
358 List<IntType>
unpack(const labelRange&
range) const;
363 template<class IntType =
unsigned int>
370 inline
void fill(const
unsigned int val);
376 inline
bool trim(label minpos = -1);
389 inline
void resize(const label numElem, const
unsigned int val = 0u);
397 inline
void reserve(const label numElem);
471 Ostream&
writeList(Ostream& os, label shortLen=0) const;
474 void writeEntry(const word& keyword, Ostream& os) const;
480 inline
void push_back(const
unsigned int val);
486 inline
unsigned int remove();
490 inline
unsigned int operator[](const label i) const;
494 inline reference
operator[](const label i);
503 inline
void operator=(const
unsigned int val);
524 inline reference(
PackedList* parent,
const label index);
527 inline unsigned int get()
const;
530 inline bool set(
unsigned int val);
535 reference(
const reference&)
noexcept =
default;
538 reference(reference&&)
noexcept = default;
541 inline
void operator=(const reference& other);
544 inline
void operator=(const
unsigned int val);
547 inline
operator unsigned int () const;
560 friend Ostream& operator<< <Width>
566 friend Istream&
operator>> <Width>
595 void assign(
const unsigned int val) { this->
fill(val); }
606 PackedList<Width>&
append(
const unsigned int val)
617 template<
unsigned W
idth>
625 template<
unsigned W
idth>
626 Ostream& operator<<(Ostream& os, const PackedList<Width>& list)
633 template<
unsigned W
idth>
634 inline bool operator==(
const PackedList<Width>& a,
const PackedList<Width>&
b);
637 template<
unsigned W
idth>
638 inline bool operator!=(
const PackedList<Width>& a,
const PackedList<Width>&
b);
void setCapacity(const label numElem)
Alter the size of the underlying storage.
std::streamsize size_data() const noexcept
The number of integer blocks addressed in the raw storage. Same as num_blocks().
PackedList< Width > & append(const unsigned int val)
Append a value at the end of the list.
bool unset(const label i)
Unset the entry at specified index. A no-op and returns false for out-of-range positions (safely/sile...
std::streamsize byteSize() const noexcept
Same as size_bytes()
const char * cdata_bytes() const noexcept
A const pointer to the raw storage, reinterpreted as byte data.
A range or interval of labels defined by a start and a size.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
std::streamsize size_bytes() const noexcept
The number of bytes addressed in the raw storage including any padding.
autoPtr< PackedList< Width > > clone() const
Clone.
void setSize(const label n, unsigned int val=0u)
Alias for resize()
T * data() noexcept
Return pointer to the underlying array serving as data storage.
unsigned int remove()
Remove and return the last element.
static constexpr unsigned bits_per_block
The number of bits in a single block.
List< IntType > unpack() const
Return the values as a list of integral type.
static constexpr unsigned element_width
The width of an individual element (in bits).
void setPair(Istream &is)
Read an index/value pair and set accordingly.
bool uniform() const
True if all entries have identical values (and list is non-empty)
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
const block_type * cdata() const noexcept
A const pointer to the raw storage.
UList< label > labelUList
A UList of labels.
List< block_type > block_container
The internal container for storing the blocks.
void shrink_to_fit()
Shrink the allocated space to what is actually used.
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
label first_block() const
Find the first block with a '1' bit.
block_type * data() noexcept
A pointer to the raw storage.
Ostream & writeList(Ostream &os, label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
unsigned int const_reference
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
static unsigned int repeated_value(unsigned val)
Enforce non-zero Width to fit within the block storage and require at least 2 items per storage block...
void writeEntry(Ostream &os) const
Write as a dictionary entry.
constexpr PackedList() noexcept
Default construct, zero-sized and no allocation.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Istream & operator>>(Istream &, directionInfo &)
void fill(const unsigned int val)
Assign all entries to the given value.
static unsigned int readValue(Istream &is)
Read a list entry (allows for specialization)
label size_
Number of entries used.
unsigned operator()(const PackedList< Width > &obj) const
bool set(const label i, unsigned int val=~0u)
Set value at specified index, default value set is the max_value.
void clear()
Clear the list, i.e. set addressable size to zero.
labelList values() const
Return the values as a list of labels.
label first_not_block() const
Find the first block with a '0' bit.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
void reserve(const label numElem)
Reserve allocation space for at least this size (uses a size doubling strategy).
void assign(const unsigned int val)
Deprecated(2020-11) use fill()
void swap(PackedList< Width > &rhs)
Swap contents with argument.
friend Ostream & operator(Ostream &os, const InfoProxy< PackedList< Width >> &info)
static constexpr block_type max_value
The max value for an element which is also the bit-mask of the individual element.
unsigned int block_type
The storage block type for bit elements.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins's 96-bit mixer hashing function (lookup3)
decomposeUsingBbs false
Use bounding boxes (default) or unique decomposition of triangles (i.e. do not duplicate triangles) ...
char * data_bytes() noexcept
A pointer to the raw storage, reinterpreted as byte data.
A helper class for outputting values to Ostream.
tmp< GeometricField< Type, faPatchField, areaMesh > > operator &(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
void resize_nocopy(const label numElem)
Currently identical to resize. Subject to future change (Oct-2021)
Macro definitions for declaring ClassName(), NamespaceName(), etc.
void reserve_exact(const label numElem)
Reserve allocation space for at least this size (uses the specified size without any other resizing s...
InfoProxy< PackedList< Width > > info() const noexcept
Return info proxy, used to print information to a stream.
const List< block_type > & storage() const noexcept
Return the underlying storage blocks.
block_container blocks_
The blocks of raw data.
static constexpr block_type mask_lower(unsigned elementOffset)
Masking for all bits below the element offset.
void push_back(const unsigned int val)
Append a value at the end of the list.
void clearStorage()
Clear the list and delete storage.
void copyAssign(const PackedList< Width > &rhs)
Copy assignment.
bool operator!=(const eddy &a, const eddy &b)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
bool equal(const PackedList< Width > &other) const
Test for equality of sizes and the bits set.
void reset()
Clear all bits but do not adjust the addressable size.
static constexpr unsigned elem_per_block
The number of elements stored per data block.
void clear_trailing_bits()
Clear any partial rubbish in the last addressable block.
Number of items before requiring line-breaks in the list output.
List< label > labelList
A List of labels.
label num_blocks() const noexcept
The number of internal storage blocks.
void transfer(PackedList< Width > &rhs)
Transfer the contents of the argument list into this list and annul the argument list.
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
bool trim(label minpos=-1)
Trim any trailing zero elements, optionally specifying a a minimum position, below which trimming wil...
Istream & readList(Istream &is)
Clear list and read from stream.
label capacity() const noexcept
Number of elements that can be stored without reallocating.
unsigned int get(const label i) const
Get value at specified index. A no-op and returns 0 for out-of-range positions (safely/silently ignor...
void shrink()
Alias for shrink_to_fit()
Ostream & printBits(Ostream &os, bool debugOutput=false) const
Print bit patterns, optionally with extra debug.
label size() const noexcept
Number of entries.
void checkIndex(const label i) const
Check index is within valid range [0,size)
ClassNameNoDebug("PackedList")
Define template name.
Template-invariant parts for PackedList.
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.