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 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;
495 template<
unsigned nBits>
498 StorageList::operator=(lst);
503 template<
unsigned nBits>
510 template<
unsigned nBits>
513 setCapacity(lst.
size());
523 template<
unsigned nBits>
526 setCapacity(lst.
size());
538 template<
unsigned nBits>
547 template<
unsigned nBits>
554 template<
unsigned nBits>
555 Foam::Ostream& Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
557 return lst.
write(os,
false);
Ostream & printInfo(Ostream &, const bool fullOutput=false) const
Print information and bit patterns (with printBits)
void flip()
Invert the bits in the addressable region.
#define forAll(list, i)
Loop across all elements in list.
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.
punctuationToken pToken() const
virtual Ostream & write(const char)=0
Write character.
FvWallInfoData< WallInfo, label > 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)
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)
const T * cdata() const
Return a const pointer to the first data element,.
InfoProxy< token > info() const
Return info proxy.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
A token holds items read from Istream.
void putBack(const token &)
Put back token.
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
const dimensionedScalar c
Speed of light in a vacuum.
Istream & read(Istream &)
Clear list and read from stream.
std::streamsize byteSize() const
Return the binary size in number of characters.
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.
#define COUNT_PACKEDBITS(sum, x)
label size() const
Return the number of elements in the list.
Istream & operator>>(Istream &, directionInfo &)
static unsigned int readValue(Istream &)
Read a list entry (allows for specialisation)
streamFormat format() const
Return current stream format.
char readBeginList(const char *funcName)
void clear()
Clear the list, i.e. set addressable size to zero.
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
labelList values() const
Return the values as a list of labels.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
The const_iterator for PackedList.
unsigned int count() const
Count number of bits set, O(log(n))
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.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
A List with indirect addressing.
label size() const
Number of entries.
void setPair(Istream &)
Read an index/value pair and set accordingly.
label size() const
Return the number of elements in the UList.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
Ostream & printInfo(Ostream &) const
Print information and values.
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
bool isPunctuation() const