32 #if (UINT_MAX == 0xFFFFFFFF)
34 #define COUNT_PACKEDBITS(sum, x) \
36 x -= (x >> 1) & 0x55555555; \
37 x = (x & 0x33333333) + ((x >> 2) & 0x33333333); \
38 sum += (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; \
40 #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF)
42 #define COUNT_PACKEDBITS(sum, x) \
44 x -= (x >> 1) & 0x5555555555555555; \
45 x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); \
46 sum += (((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56;\
50 #define COUNT_PACKEDBITS(sum, x) for (; x; ++sum) { x &= x - 1; }
54 template<
unsigned nBits>
61 const label packLen = packedLength();
62 for (
label i = 0; i < packLen; ++i)
64 unsigned int bits = StorageList::operator[](i);
73 template<
unsigned nBits>
81 const label oldSize = size_;
82 for (
label storeI = packedLength()-1; storeI >= 0; --storeI)
84 size_ = storeI * packing();
85 unsigned int bits = StorageList::operator[](storeI);
99 return (size_ != oldSize);
103 template<
unsigned nBits>
112 const unsigned int mask = maskLower(packing());
114 const label packLen = packedLength();
115 for (
label i=0; i < packLen; ++i)
117 StorageList::operator[](i) = mask & ~
StorageList::operator[](i);
122 const unsigned int off = size_ % packing();
125 const unsigned int seg = size_ / packing();
127 StorageList::operator[](seg) &= maskLower(off);
133 template<
unsigned nBits>
147 template<
unsigned nBits>
153 os <<
"iterator<" <<
label(nBits) <<
"> ["
157 <<
" value:" << this->
get()
164 template<
unsigned nBits>
168 const bool fullOutput
178 for (
label i=0; i < outputLen; ++i)
185 const unsigned int off = size_ %
packing();
192 else if (i == packLen)
199 for (
unsigned int testBit = (1u <<
max_bits()); testBit; testBit >>= 1)
204 if (rawBits & testBit)
215 if (rawBits & testBit)
233 template<
unsigned nBits>
237 const bool fullOutput
240 os <<
"PackedList<" << nBits <<
">"
244 <<
" size/capacity: " << size_ <<
"/" <<
capacity() <<
nl
245 <<
" storage/capacity: "
253 template<
unsigned nBits>
259 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
264 "PackedList<nBits>::read(Istream&) : "
265 "reading first token"
279 const char delimiter = is.
readBeginList(
"PackedList<nBits>");
285 for (
label i=0; i<sz; ++i)
291 "PackedList<nBits>::read(Istream&) : "
303 "PackedList<nBits>::read(Istream&) : "
304 "reading the single entry"
310 <<
"incorrect list token, expected '(' or '{', found "
331 "PackedList<nBits>::read(Istream&) : "
332 "reading the binary block"
342 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
346 !( nextTok.isPunctuation()
355 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
361 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
365 !( nextTok.isPunctuation()
374 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
380 <<
"incorrect first token, expected '(', found "
388 <<
"incorrect first token, expected <int>, '(' or '{', found "
397 template<
unsigned nBits>
401 const bool indexedOutput
410 bool uniform =
false;
412 if (sz > 1 && !indexedOutput)
418 if (lst[i] != lst[0])
431 else if (indexedOutput)
443 if (iter.writeIfSet(os))
478 os <<
nl << sz <<
nl;
495 template<
unsigned nBits>
503 template<
unsigned nBits>
510 template<
unsigned nBits>
523 template<
unsigned nBits>
538 template<
unsigned nBits>
547 template<
unsigned nBits>
554 template<
unsigned nBits>
557 return lst.
write(os,
false);
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
#define COUNT_PACKEDBITS(sum, x)
#define forAll(list, i)
Loop across all elements in list.
streamFormat format() const
Return current stream format.
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
char readEndList(const char *funcName)
virtual Istream & read(token &)=0
Return next token from stream.
char readBeginList(const char *funcName)
void putBack(const token &)
Put back token.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
label size() const
Return the number of elements in the UList.
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & write(const char)=0
Write character.
The const_iterator for PackedList.
Ostream & printInfo(Ostream &) const
Print information and values.
label index_
Element index.
unsigned int get() const
Get value as unsigned, no range-checking.
A dynamically allocatable list of packed unsigned integers.
static unsigned int max_value()
The max. value for an entry, which simultaneously the bit-mask.
void flip()
Invert the bits in the addressable region.
List< unsigned int > & storage()
Return the underlying packed storage.
bool set(const label, const unsigned int val=~0u)
Set value at index I. Return true if value changed.
static unsigned int maskLower(unsigned offset)
Masking for all bits below the offset.
Istream & read(Istream &)
Clear list and read from stream.
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
void setCapacity(const label)
Alter the size of the underlying storage.
labelList values() const
Return the values as a list of labels.
label size() const
Number of entries.
void transfer(PackedList< nBits > &)
Transfer the contents of the argument list into this list.
label capacity() const
The number of elements that can be stored before reallocating.
bool trim()
Trim any trailing zero elements.
label packedLength() const
The list length when packed.
void setPair(Istream &)
Read an index/value pair and set accordingly.
static unsigned int packing()
The number of entries per packed storage element.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
static unsigned int max_bits()
The max. number of bits that can be templated.
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
void operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
std::streamsize byteSize() const
Return the binary size in number of characters.
static unsigned int readValue(Istream &)
Read a list entry (allows for specialisation)
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
void clear()
Clear the list, i.e. set addressable size to zero.
unsigned int count() const
Count number of bits set, O(log(n))
Ostream & printInfo(Ostream &, const bool fullOutput=false) const
Print information and bit patterns (with printBits)
Ostream & printBits(Ostream &, const bool fullOutput=false) const
Print bit patterns, optionally output unused elements.
Ostream & write(Ostream &, const bool indexedOutput=false) const
Write, optionally with indexedOutput.
A List with indirect addressing.
label size() const
Return the number of elements in the list.
label size() const
Return the number of elements in the UList.
T & operator[](const label)
Return element of UList.
const T * cdata() const
Return a const pointer to the first data element,.
T * data()
Return a pointer to the first data element,.
A token holds items read from Istream.
bool isPunctuation() const
punctuationToken pToken() const
InfoProxy< token > info() const
Return info proxy.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const dimensionedScalar c
Speed of light in a vacuum.
errorManipArg< error, int > exit(error &err, const int errNo=1)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Istream & operator>>(Istream &, directionInfo &)
Ostream & operator<<(Ostream &, const ensightPart &)