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" 310 <<
"incorrect list token, expected '(' or '{', found " 331 "PackedList<nBits>::read(Istream&) : " 332 "reading the binary block" 339 if (firstTok.
pToken() == token::BEGIN_LIST)
342 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
347 && nextTok.
pToken() == token::END_LIST
355 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
358 else if (firstTok.
pToken() == token::BEGIN_BLOCK)
361 is.
fatalCheck(
"PackedList<nBits>::read(Istream&)");
366 && nextTok.
pToken() == token::END_BLOCK
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
408 if (os.
format() == IOstream::ASCII)
412 if (sz > 1 && !indexedOutput)
418 if (lst[i] != lst[0])
429 os << sz << token::BEGIN_BLOCK << lst[0] << token::END_BLOCK;
431 else if (indexedOutput)
434 os <<
nl << token::BEGIN_BLOCK <<
nl;
443 if (iter.writeIfSet(os))
449 os << token::END_BLOCK <<
nl;
454 os << sz << token::BEGIN_LIST;
463 os << token::END_LIST;
468 os <<
nl << sz <<
nl << token::BEGIN_LIST;
473 os <<
nl << token::END_LIST <<
nl;
478 os <<
nl << sz <<
nl;
493 template<
unsigned nBits>
500 template<
unsigned nBits>
509 os << token::END_STATEMENT <<
endl;
515 template<
unsigned nBits>
518 StorageList::operator=(lst);
523 template<
unsigned nBits>
526 setCapacity(lst.
size());
536 template<
unsigned nBits>
539 setCapacity(lst.
size());
551 template<
unsigned nBits>
558 template<
unsigned nBits>
559 Foam::Ostream& Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
561 return lst.
write(os,
false);
unsigned int count() const
Count number of bits set, O(log(n))
A simple container for copying or transferring objects of type <T>.
void flip()
Invert the bits in the addressable region.
#define forAll(list, i)
Loop across all elements in list.
streamFormat format() const
Return current stream format.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
char readEndList(const char *funcName)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
A token holds items read from Istream.
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
void putBack(const token &)
Put back token.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Istream & read(Istream &)
Clear list and read from stream.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
virtual Istream & read(token &)=0
Return next token from stream.
A dynamically allocatable list of packed unsigned integers.
A class for handling words, derived from string.
#define COUNT_PACKEDBITS(sum, x)
punctuationToken pToken() const
Istream & operator>>(Istream &, directionInfo &)
static unsigned int readValue(Istream &)
Read a list entry (allows for specialization)
label size() const
Return the number of elements in the list.
const T * cdata() const
Return a const pointer to the first data element,.
Ostream & printInfo(Ostream &, const bool fullOutput=false) const
Print information and bit patterns (with printBits)
void writeEntry(Ostream &) const
Write as a dictionary entry.
char readBeginList(const char *funcName)
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...
Ostream & write(Ostream &, const bool indexedOutput=false) const
Write, optionally with indexedOutput.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
std::streamsize byteSize() const
Return the binary size in number of characters.
Ostream & printBits(Ostream &, const bool fullOutput=false) const
Print bit patterns, optionally output unused elements.
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
Xfer< labelList > values() const
Return the values as a list of labels.
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
The const_iterator for PackedList.
label size() const
Return the number of elements in the UList.
bool trim()
Trim any trailing zero elements.
T * data()
Return a pointer to the first data element,.
List< unsigned int > & storage()
Return the underlying packed storage.
void operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
InfoProxy< token > info() const
Return info proxy.
A List with indirect addressing.
const dimensionedScalar c
Speed of light in a vacuum.
virtual Ostream & write(const token &)=0
Write next token to stream.
void setPair(Istream &)
Read an index/value pair and set accordingly.
Ostream & printInfo(Ostream &) const
Print information and values.
bool isPunctuation() const
label size() const
Number of entries.
void fatalCheck(const char *operation) const
Check IOstream status for given operation.