diff --git a/applications/test/HashTable/Make/files b/applications/test/HashTable/Make/files deleted file mode 100644 index 53d1e07699..0000000000 --- a/applications/test/HashTable/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -Test-hashTable.C - -EXE = $(FOAM_USER_APPBIN)/Test-hashTable diff --git a/applications/test/HashTable1/Make/files b/applications/test/HashTable1/Make/files new file mode 100644 index 0000000000..05c776d65c --- /dev/null +++ b/applications/test/HashTable1/Make/files @@ -0,0 +1,3 @@ +Test-HashTable1.C + +EXE = $(FOAM_USER_APPBIN)/Test-HashTable1 diff --git a/applications/test/HashTable/Make/options b/applications/test/HashTable1/Make/options similarity index 100% rename from applications/test/HashTable/Make/options rename to applications/test/HashTable1/Make/options diff --git a/applications/test/HashTable/Test-hashTable.C b/applications/test/HashTable1/Test-HashTable1.C similarity index 100% rename from applications/test/HashTable/Test-hashTable.C rename to applications/test/HashTable1/Test-HashTable1.C diff --git a/applications/test/HashTable4/Make/files b/applications/test/HashTable4/Make/files new file mode 100644 index 0000000000..fcc01c49bd --- /dev/null +++ b/applications/test/HashTable4/Make/files @@ -0,0 +1,3 @@ +Test-HashTable4.C + +EXE = $(FOAM_USER_APPBIN)/Test-HashTable4 diff --git a/applications/test/HashTable4/Make/options b/applications/test/HashTable4/Make/options new file mode 100644 index 0000000000..6a9e9810b3 --- /dev/null +++ b/applications/test/HashTable4/Make/options @@ -0,0 +1,2 @@ +/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */ +/* EXE_LIBS = -lfiniteVolume */ diff --git a/applications/test/HashTable4/Test-HashTable4.C b/applications/test/HashTable4/Test-HashTable4.C new file mode 100644 index 0000000000..b9333f320d --- /dev/null +++ b/applications/test/HashTable4/Test-HashTable4.C @@ -0,0 +1,312 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Description + Test HashTable resizing + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "HashSet.H" +#include "HashTable.H" +#include "Map.H" +#include "cpuTime.H" +#include "memInfo.H" + +#include +#include +#include +#include + +// #undef ORDERED +// #define ORDERED + +using namespace Foam; + +template +Ostream& printInfo(Ostream& os, const HashTable>& ht) +{ + os << " (size " << ht.size() << " capacity " << ht.capacity() << ") "; + return os; +} + + +template +inline void insertElem +( + #ifdef ORDERED + std::set& container, + #else + std::unordered_set>& container, + #endif + K k, + V v +) +{ + container.insert(k); +} + + +template +inline void insertElem +( + #ifdef ORDERED + std::map& container, + #else + std::unordered_map>& container, + #endif + K k, + V v +) +{ + container.insert(std::make_pair(k, v)); +} + + +template +inline void insertElem +( + HashSet>& container, + K k, + V v +) +{ + container.insert(k); +} + + +template +inline void insertElem +( + HashTable>& container, + K k, + V v +) +{ + container.insert(k, v); +} + + +template +inline void loopInsert(Container& container, const label n) +{ + for (label i = 0; i < n; i++) + { + insertElem(container, i, i); + } +} + + +template +inline unsigned long loopFind(const Container& container, const label n) +{ + const auto endIter = container.end(); + unsigned long sum = 0; + + for (label i = 0; i < n; i++) + { + if (container.find(i) != endIter) + { + ++sum; + } + } + + return sum; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + const label nLoops = 200; + const label nFind = 10; + const label nElem = 1000000; + + argList::noBanner(); + argList::addBoolOption("std", "use std::unordered_map or std::set"); + argList::addBoolOption("set", "test HashSet"); + argList::addBoolOption("find", "test find"); + + argList args(argc, argv); + + const bool optStd = args.optionFound("std"); + const bool optSet = args.optionFound("set"); + const bool optFnd = args.optionFound("find"); + + + cpuTime timer; + memInfo mem; + + Info<< "insert " << nElem << " (int) elements"; + if (optFnd) + { + Info<< ", then find " << (nFind*nLoops) << " times\n"; + } + else + { + Info<< " repeated " << nLoops << " times " << endl; + } + + if (false) + { + // verify that resizing around (0) doesn't fail + HashTable> map(32); + printInfo(Info, map) << endl; + + map.insert(10, 1000); + + map.resize(0); + printInfo(Info, map) << endl; + + map.resize(10); + printInfo(Info, map) << endl; + + map.clear(); + printInfo(Info, map) << endl; + + map.resize(0); + printInfo(Info, map) << endl; + return 0; + } + + + if (optStd) + { + if (optFnd) + { + #ifdef ORDERED + Info<< "using stl::set" << endl; + std::set