diff --git a/applications/test/PackedList/PackedListTest.C b/applications/test/PackedList/PackedListTest.C index 62bf38d521..e598337b07 100644 --- a/applications/test/PackedList/PackedListTest.C +++ b/applications/test/PackedList/PackedListTest.C @@ -38,7 +38,6 @@ using namespace Foam; int main(int argc, char *argv[]) { - bool changed; Info<< "PackedList max_bits() = " << PackedList<0>::max_bits() << nl; Info<< "\ntest allocation with value\n"; @@ -46,7 +45,42 @@ int main(int argc, char *argv[]) list1.print(Info); Info<< "\ntest assign uniform value\n"; - list1 = 4; + list1 = 3; + list1.print(Info); + + Info<< "\ntest assign uniform value (with overflow)\n"; + list1 = -1; + list1.print(Info); + + Info<< "\ntest assign between references - does not work as expected\n"; + list1[2] = 3; + list1[4] = list1[2]; + list1.print(Info); + + { + const PackedList<3>& constLst = list1; + Info<< "\ntest operator[] const with out-of-range index\n"; + constLst.print(Info); + if (!constLst[20]) + { + Info<< "[20] is false, as expected\n"; + } + constLst.print(Info); + + Info<< "\ntest operator[] non-const with out-of-range index\n"; + if (!list1[20]) + { + Info<< "[20] is false, as expected but list was resized!! (non-const)\n"; + } + list1.print(Info); + } + + + Info<< "\ntest operator[] with out-of-range index\n"; + if (!list1[20]) + { + Info<< "[20] is false, as expected\n"; + } list1.print(Info); Info<< "\ntest resize with value (without reallocation)\n"; @@ -111,6 +145,10 @@ int main(int argc, char *argv[]) list1.setCapacity(24); list1.print(Info); + Info<< "\ntest trim\n"; + list1.trim(); + list1.print(Info); + // add in some misc values list1[31] = 1; list1[32] = 2; @@ -122,12 +160,10 @@ int main(int argc, char *argv[]) iter.print(Info) << "\n"; Info<< "\ntest iterator operator=\n"; - changed = (iter = 5); + iter = 2; Info<< "iterator:" << iter() << "\n"; - Info<< "changed:" << changed << "\n"; - changed = (iter = 5); - Info<< "changed:" << changed << "\n"; + iter = 5; list1.print(Info); Info<< "\ntest get() method\n"; @@ -137,12 +173,13 @@ int main(int argc, char *argv[]) Info<< "\ntest iterator indexing\n"; Info<< "cend() "; list1.cend().print(Info) << "\n"; - - for + + for ( PackedList<3>::const_iterator cit = list1[30]; cit != list1.cend(); - ++cit) + ++cit + ) { cit.print(Info); } @@ -167,7 +204,7 @@ int main(int argc, char *argv[]) Info<< "\ntest pattern that fills all bits\n"; PackedList<4> list3(8, 8); - + label pos = list3.size() - 1; list3[pos--] = list3.max_value(); diff --git a/applications/test/PackedList2/PackedListTest2.C b/applications/test/PackedList2/PackedListTest2.C index ed86a0778a..61bd2530db 100644 --- a/applications/test/PackedList2/PackedListTest2.C +++ b/applications/test/PackedList2/PackedListTest2.C @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) std::vector stlVector(n, true); labelHashSet emptyHash; - labelHashSet fullHash; + labelHashSet fullHash(1000); for(label i = 0; i < n; i++) { fullHash.insert(i); @@ -70,6 +70,35 @@ int main(int argc, char *argv[]) } Info<< "resize/shrink/resize:" << timer.cpuTimeIncrement() << " s\n\n"; + // set every other bit on: + Info<< "set every other bit on and count\n"; + packed.storage() = 0xAAAAAAAAu; + + // Count packed + sum = 0; + for (label iter = 0; iter < nIters; iter++) + { + forAll(packed, i) + { + sum += packed[i]; + } + } + Info<< "Counting brute-force:" << timer.cpuTimeIncrement() + << " s" << endl; + Info<< " sum " << sum << endl; + + + // Count packed + sum = 0; + for (label iter = 0; iter < nIters; iter++) + { + sum += packed.count(); + } + Info<< "Counting via count():" << timer.cpuTimeIncrement() + << " s" << endl; + Info<< " sum " << sum << endl; + + // Dummy addition sum = 0; for (label iter = 0; iter < nIters; iter++) @@ -182,7 +211,7 @@ int main(int argc, char *argv[]) sum = 0; for (label iter = 0; iter < nIters; iter++) { - forAll(packed, i) + forAll(unpacked, i) { sum += emptyHash.found(i); } @@ -196,7 +225,7 @@ int main(int argc, char *argv[]) sum = 0; for (label iter = 0; iter < nIters; iter++) { - forAll(packed, i) + forAll(unpacked, i) { sum += fullHash.found(i); } @@ -206,7 +235,6 @@ int main(int argc, char *argv[]) Info<< " sum " << sum << endl; - // // Write // @@ -326,8 +354,7 @@ int main(int argc, char *argv[]) Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement() << " s" << endl; - - + Info << "End\n" << endl; return 0; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 8fe778aa16..2c4bfce8d7 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -50,7 +50,7 @@ primitives/random/Random.C containers/HashTables/HashTable/HashTableName.C containers/HashTables/StaticHashTable/StaticHashTableName.C containers/Lists/SortableList/ParSortableListName.C -containers/Lists/PackedList/PackedListName.C +containers/Lists/PackedList/PackedListCore.C containers/Lists/ListOps/ListOps.C containers/LinkedLists/linkTypes/SLListBase/SLListBase.C containers/LinkedLists/linkTypes/DLListBase/DLListBase.C diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C index c9b0f3bb6d..ced308eaff 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C @@ -53,6 +53,115 @@ Foam::PackedList::PackedList(const UList