Go to the documentation of this file.
39 int main(
int argc,
char *argv[])
43 Info<<
"\ntest allocation with value\n";
47 Info<<
"\ntest assign uniform value\n";
51 Info<<
"\ntest assign uniform value (with overflow)\n";
55 Info<<
"\ntest zero\n";
59 Info<<
"\ntest set() with default argument (max_value)\n";
64 Info<<
"\ntest unset() with in-range and out-of-range\n";
69 Info<<
"\ntest assign between references\n";
74 Info<<
"\ntest assign between references, with chaining\n";
75 list1[0] = list1[4] = 1;
78 Info<<
"\ntest assign between references, with chaining and auto-vivify\n";
79 list1[1] = list1[8] = list1[10] = list1[14] = 2;
83 Info<<
"\ntest operator== between references\n";
84 if (list1[1] == list1[8])
86 Info<<
"[1] == [8] (expected)\n";
90 Info<<
"[1] != [8] (unexpected)\n";
93 if (list1[0] != list1[1])
95 Info<<
"[0] != [1] (expected)\n";
99 Info<<
"[0] == [1] (unexpected)\n";
102 Info<<
"\ntest operator== with iterator\n";
106 if (iter != list1[8])
108 Info<<
"iter != [8] (expected)\n";
112 Info<<
"iter == [8] (unexpected)\n";
115 if (*iter != list1[8])
117 Info<<
"*iter != [8] (unexpected)\n";
121 Info<<
"*iter == [8] (expected)\n";
128 Info<<
"\ntest operator[] const with out-of-range index\n";
132 Info<<
"[20] is true (unexpected)\n";
136 Info<<
"[20] is false (expected) list size should be unchanged "
141 Info<<
"\ntest operator[] non-const with out-of-range index\n";
144 Info<<
"[20] is true (unexpected)\n";
148 Info<<
"[20] is false (expected) but list was resized?? "
155 Info<<
"\ntest operator[] with out-of-range index\n";
158 Info<<
"[20] is false, as expected\n";
162 Info<<
"\ntest resize with value (without reallocation)\n";
166 Info<<
"\ntest flip() function\n";
170 Info<<
"\nre-flip()\n";
174 Info<<
"\ntest set() function\n";
178 Info<<
"\ntest assign bool\n";
182 Info<<
"\ntest assign bool\n";
186 Info<<
"\ntest resize without value (with reallocation)\n";
190 Info<<
"\ntest resize with value (with reallocation)\n";
194 Info<<
"\ntest resize smaller (should not touch allocation)\n";
198 Info<<
"\ntest append() operation\n";
204 Info<<
"\ntest reserve() operation\n";
208 Info<<
"\ntest shrink() operation\n";
212 Info<<
"\ntest setCapacity() operation\n";
216 Info<<
"\ntest setCapacity() operation\n";
220 Info<<
"\ntest operator[] assignment\n";
224 Info<<
"\ntest operator[] assignment with auto-vivify\n";
228 Info<<
"\ntest setCapacity smaller\n";
232 Info<<
"\ntest resize much smaller\n";
236 Info<<
"\ntest trim\n";
245 Info<<
"\ntest iterator\n";
250 Info<<
"iterator:" << iter() <<
"\n";
256 Info<<
"iterator:" << iter() <<
"\n";
260 Info<<
"\ntest get() method\n";
261 Info<<
"get(10):" << list1.
get(10) <<
" and list[10]:" << list1[10] <<
"\n";
264 Info<<
"\ntest iterator indexing\n";
269 Info<<
"\ntest assignment of iterator\n";
274 Info<<
"out-of-range: ";
279 Info<<
"out-of-range: ";
295 Info<<
"\ntest operator[] auto-vivify\n";
296 Info<<
"size:" << list1.
size() <<
"\n";
298 const unsigned int val = list1[45];
300 Info<<
"list[45]:" << val <<
"\n";
301 Info<<
"size after read:" << list1.
size() <<
"\n";
304 Info<<
"size after write:" << list1.
size() <<
"\n";
305 Info<<
"list[45]:" << list1[45] <<
"\n";
306 list1[49] = list1[100];
310 Info<<
"\ntest copy constructor + append\n";
313 Info<<
"source list:\n";
314 list1.printInfo(
Info,
true);
315 Info<<
"destination list:\n";
318 Info<<
"\ntest pattern that fills all bits\n";
343 Info<<
"\ntest operator[] const with out-of-range index\n";
347 Info<<
"[100] is true (unexpected)\n";
351 Info<<
"[100] is false (expected) "
352 <<
"list size should be unchanged (const)\n";
360 Info<<
"copied from bool list " <<
endl;
366 Info<<
"indices: " << indices <<
endl;
370 Info<<
"\n\nDone.\n";
bool unset(const label)
Unset the entry at index I. Return true if value changed.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
#define forAll(list, i)
Loop across all elements in list.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
Ostream & endl(Ostream &os)
Add newline and flush stream.
void setCapacity(const label)
Alter the size of the underlying storage.
static unsigned int max_bits()
The max. number of bits that can be templated.
void reserve(const label)
Reserve allocation space for at least this size.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
The iterator class used for PackedList.
void flip()
Invert the bits in the addressable region.
unsigned int remove()
Remove and return the last element.
iterator begin()
Iterator set to the beginning of the PackedList.
bool set(const label, const unsigned int val=~0u)
Set value at index I. Return true if value changed.
bool trim()
Trim any trailing zero elements.
unsigned int get(const label) const
Get value at index I.
Ostream & printInfo(Ostream &, const bool fullOutput=false) const
Print information and bit patterns (with printBits)
Ostream & printInfo(Ostream &) const
Print information and values.
static unsigned int max_value()
The max. value for an entry, which simultaneously the bit-mask.
iterator end()
Iterator set to beyond the end of the PackedList.
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
int main(int argc, char *argv[])
A dynamically allocatable list of packed unsigned integers.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
void shrink()
Shrink the allocated space to what is actually used.
label size() const
Number of entries.
Xfer< labelList > used() const
Return indices of the used (true) elements as a list of labels.
dimensionedScalar pos(const dimensionedScalar &ds)