93 #ifndef Foam_PackedList_H 94 #define Foam_PackedList_H 102 #include <type_traits> 113 template<
unsigned W
idth>
116 template<
unsigned W
idth>
117 Ostream& operator<<(Ostream& os, const PackedList<Width>& list);
119 template<
unsigned W
idth>
120 Ostream& operator<<(Ostream& os, const InfoProxy<PackedList<Width>>& info);
144 template<
unsigned W
idth>
160 = (std::numeric_limits<block_type>::digits);
216 "Width must be > 0 and minimum of two items per data block" 265 inline explicit
PackedList(const label numElem);
269 inline
PackedList(const label numElem, const
unsigned int val);
332 inline
unsigned int get(const label i) const;
337 inline
bool set(const label i,
unsigned int val = ~0u);
342 inline
bool unset(const label i);
349 template<class IntType =
unsigned int>
350 List<IntType>
unpack() const;
354 template<class IntType =
unsigned int>
355 List<IntType>
unpack(const labelRange&
range) const;
360 template<class IntType =
unsigned int>
367 inline
void fill(const
unsigned int val);
373 inline
bool trim(label minpos = -1);
386 inline
void resize(const label numElem, const
unsigned int val = 0u);
394 inline
void reserve(const label numElem);
469 inline
void push_back(const
unsigned int val);
475 inline
unsigned int remove();
479 inline
unsigned int operator[](const label i) const;
483 inline reference
operator[](const label i);
492 inline
void operator=(const
unsigned int val);
513 inline reference(
PackedList* parent,
const label index);
516 inline unsigned int get()
const;
519 inline bool set(
unsigned int val);
524 reference(
const reference&) =
default;
527 reference(reference&&) =
default;
530 inline void operator=(
const reference& other);
533 inline void operator=(
const unsigned int val);
536 inline operator unsigned int ()
const;
549 friend Ostream& operator<< <Width>
552 const InfoProxy<PackedList<Width>>&
info 555 friend Istream&
operator>> <Width>
558 PackedList<Width>& list
568 unsigned operator()(
const PackedList<Width>& obj)
const 584 void assign(
const unsigned int val) { this->
fill(val); }
588 void assign(
const PackedList<Width>& rhs) { (*this) = rhs; }
595 PackedList<Width>&
append(
const unsigned int val)
606 template<
unsigned W
idth>
607 struct Hash<PackedList<Width>> : PackedList<Width>::hasher {};
614 template<
unsigned W
idth>
615 Ostream& operator<<(Ostream& os, const PackedList<Width>& list)
617 return list.
writeList(
os, Detail::ListPolicy::short_length<void>::value);
622 template<
unsigned W
idth>
623 inline bool operator==(
const PackedList<Width>& a,
const PackedList<Width>&
b);
626 template<
unsigned W
idth>
627 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.
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 index i.
std::streamsize byteSize() const noexcept
The number of bytes used in the raw storage including any unused padding.
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 used in the raw storage including any unused padding.
autoPtr< PackedList< Width > > clone() const
Clone.
const List< unsigned int > & storage() const
Return the underlying storage blocks.
void setSize(const label n, unsigned int val=0u)
Alias for resize()
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.
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
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...
UList< label > labelUList
A UList of labels.
List< block_type > block_container
The internal container for storing the blocks.
label nBlocks() const
The number of internal storage blocks.
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.
unsigned int const_reference
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].
A class for handling words, derived from Foam::string.
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 index i, 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()
OBJstream os(runTime.globalPath()/outputName)
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)
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.
unsigned int * data() noexcept
A pointer to the raw storage.
InfoProxy< PackedList< Width > > info() const noexcept
Return info proxy, used to print information to a stream.
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.
static constexpr label num_blocks(label numElem) noexcept
Calculate the number of blocks required to _address_ the requested number of elements.
bool operator!=(const eddy &a, const eddy &b)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
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.
List< label > labelList
A List of labels.
const unsigned int * cdata() const noexcept
A const pointer to the raw storage.
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.
void operator=(const PackedList< Width > &list)
Copy assignment.
label capacity() const noexcept
Number of elements that can be stored without reallocating.
unsigned int get(const label i) const
Get value at index i or 0 for out-of-range.
void shrink()
Shrink the allocated space to what is actually used.
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.