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) <<
"> [" 154 << this->index_ <<
"]" 155 <<
" segment:" <<
label(this->index_ / packing())
156 <<
" offset:" <<
label(this->index_ % packing())
157 <<
" value:" << this->
get()
164 template<
unsigned nBits>
168 const bool fullOutput
171 const label packLen = packedLength();
174 unsigned int mask = maskLower(packing());
175 const label outputLen = fullOutput ? StorageList::size() : packLen;
178 for (
label i=0; i < outputLen; ++i)
180 const StorageType& rawBits = StorageList::operator[](i);
185 const unsigned int off = size_ % packing();
189 mask = maskLower(off);
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 <<
">" 241 <<
" max_value:" << max_value()
242 <<
" packing:" << packing() <<
nl 243 <<
" count: " << count() <<
nl 244 <<
" size/capacity: " << size_ <<
"/" << capacity() <<
nl 245 <<
" storage/capacity: " 246 << packedLength() <<
"/" << StorageList::size()
249 return printBits(os, fullOutput);
253 template<
unsigned nBits>
259 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
264 "PackedList<nBits>::read(Istream&) : " 265 "reading first token" 276 if (is.
format() == IOstream::ASCII)
279 const char delimiter = is.
readBeginList(
"PackedList<nBits>");
283 if (delimiter == token::BEGIN_LIST)
285 for (
label i=0; i<sz; ++i)
291 "PackedList<nBits>::read(Istream&) : " 296 else if (delimiter == token::BEGIN_BLOCK)
303 "PackedList<nBits>::read(Istream&) : " 304 "reading the single entry" 311 "PackedList<nBits>::read(Istream&)",
314 <<
"incorrect list token, expected '(' or '{', found " 335 "PackedList<nBits>::read(Istream&) : " 336 "reading the binary block" 343 if (firstTok.
pToken() == token::BEGIN_LIST)
346 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
351 && nextTok.
pToken() == token::END_LIST
359 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
362 else if (firstTok.
pToken() == token::BEGIN_BLOCK)
365 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
370 && nextTok.
pToken() == token::END_BLOCK
378 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
385 "PackedList<nBits>::read(Istream&)",
388 <<
"incorrect first token, expected '(', found " 397 "PackedList<nBits>::read(Istream&)",
400 <<
"incorrect first token, expected <int>, '(' or '{', found " 409 template<
unsigned nBits>
413 const bool indexedOutput
420 if (os.
format() == IOstream::ASCII)
424 if (sz > 1 && !indexedOutput)
430 if (lst[i] != lst[0])
441 os << sz << token::BEGIN_BLOCK << lst[0] << token::END_BLOCK;
443 else if (indexedOutput)
446 os <<
nl << token::BEGIN_BLOCK <<
nl;
455 if (iter.writeIfSet(os))
461 os << token::END_BLOCK <<
nl;
466 os << sz << token::BEGIN_LIST;
475 os << token::END_LIST;
480 os <<
nl << sz <<
nl << token::BEGIN_LIST;
485 os <<
nl << token::END_LIST <<
nl;
490 os <<
nl << sz <<
nl;
505 template<
unsigned nBits>
512 template<
unsigned nBits>
521 os << token::END_STATEMENT <<
endl;
527 template<
unsigned nBits>
531 StorageList::operator=(lst);
537 template<
unsigned nBits>
541 setCapacity(lst.
size());
552 template<
unsigned nBits>
556 setCapacity(lst.
size());
569 template<
unsigned nBits>
576 template<
unsigned nBits>
577 Foam::Ostream& Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
579 return lst.
write(os,
false);
void setPair(Istream &)
Read an index/value pair and set accordingly.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
bool trim()
Trim any trailing zero elements.
void writeEntry(Ostream &) const
Write as a dictionary entry.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
char readBeginList(const char *funcName)
A simple container for copying or transferring objects of type <T>.
virtual Istream & read(token &)=0
Return next token from stream.
Istream & read(Istream &)
Clear list and read from stream.
A class for handling words, derived from string.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
bool isPunctuation() const
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< unsigned int > & storage()
Return the underlying packed storage.
label size() const
Number of entries.
Ostream & write(Ostream &, const bool indexedOutput=false) const
Write, optionally with indexedOutput.
unsigned int count() const
Count number of bits set, O(log(n))
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
PackedList< nBits > & operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
T * data()
Return a pointer to the first data element,.
void flip()
Invert the bits in the addressable region.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Ostream & endl(Ostream &os)
Add newline and flush stream.
void putBack(const token &)
Put back token.
A List with indirect addressing.
InfoProxy< token > info() const
Return info proxy.
label size() const
Return the number of elements in the list.
char readEndList(const char *funcName)
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
static unsigned int readValue(Istream &)
Read a list entry (allows for specialization)
streamFormat format() const
Return current stream format.
virtual Ostream & write(const token &)=0
Write next token to stream.
Ostream & printInfo(Ostream &, const bool fullOutput=false) const
Print information and bit patterns (with printBits)
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
Ostream & printInfo(Ostream &) const
Print information and values.
label size() const
Return the number of elements in the UList.
A token holds items read from Istream.
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
void clear()
Clear the list, i.e. set addressable size to zero.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
const T * cdata() const
Return a const pointer to the first data element,.
Istream & operator>>(Istream &, edgeMesh &)
std::streamsize byteSize() const
Return the binary size in number of characters.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
#define COUNT_PACKEDBITS(sum, x)
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & printBits(Ostream &, const bool fullOutput=false) const
Print bit patterns, optionally output unused elements.
Uniform/equally-weighted distribution model.
punctuationToken pToken() const
A dynamically allocatable list of packed unsigned integers.
Xfer< labelList > values() const
Return the values as a list of labels.
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
The const_iterator for PackedList.