ENH: replace DictionaryBase toc with sortedToc version (#1467)

- cannot rely on the entries having a keyword method

STYLE: apply consistent hash table sizing for debug objects
This commit is contained in:
Mark Olesen 2019-10-24 17:54:45 +02:00 committed by Andrew Heather
parent 9f11d892f5
commit 5213a4aa9d
6 changed files with 35 additions and 48 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -27,7 +27,7 @@ Class
Foam::Dictionary
Description
Gerneral purpose template dictionary class which manages the storage
General purpose template dictionary class that manages the storage
associated with it.
It is derived from DictionaryBase instantiated on a memory managed form
@ -58,22 +58,21 @@ class Dictionary
:
public DictionaryBase<IDLList<T>, T>
{
public:
// Constructors
//- Construct given initial table size
Dictionary(const label size = 128);
//- Construct with given or default (128) table capacity
explicit Dictionary(const label size = 128);
//- Copy construct
Dictionary(const Dictionary&);
Dictionary(const Dictionary& dict);
// Member functions
// Member Functions
//- Remove an entry specified by keyword and delete the pointer.
// Returns true if the keyword was found
// \return true if the keyword was found
bool erase(const word& keyword);
};

View File

@ -158,15 +158,10 @@ T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword)
template<class IDLListType, class T>
Foam::wordList Foam::DictionaryBase<IDLListType, T>::toc() const
{
wordList keywords(this->size());
label i = 0;
for (auto iter = this->cbegin(); iter != this->cend(); ++iter)
{
keywords[i++] = iter().keyword();
}
return keywords;
// Cannot rely on the items themselves having a keyword() method
// so simply return the toc() from the hashed entries
// Make it sorted, since anything else would have no meaning.
return hashedTs_.sortedToc();
}

View File

@ -94,8 +94,8 @@ public:
// Constructors
//- Construct given initial table size
DictionaryBase(const label size = 128);
//- Construct with given or default (128) table capacity
explicit DictionaryBase(const label size = 128);
//- Copy construct
DictionaryBase(const DictionaryBase& dict);
@ -108,7 +108,7 @@ public:
DictionaryBase(Istream& is);
// Member functions
// Member Functions
// Search and lookup
@ -127,7 +127,7 @@ public:
//- Find and return entry
T* lookup(const word& keyword);
//- Return the table of contents
//- Return the table of contents (as a sorted list)
wordList toc() const;
//- Return the table of contents as a sorted list
@ -141,25 +141,26 @@ public:
// Editing
//- Add at head of dictionary
void insert(const word&, T*);
void insert(const word& keyword, T*);
//- Add at tail of dictionary
void append(const word&, T*);
void append(const word& keyword, T*);
//- Remove and return entry specified by keyword.
// Return nullptr if the keyword was not found.
T* remove(const word&);
T* remove(const word& keyword);
//- Clear the dictionary
void clear();
//- Transfer the contents of the argument into this DictionaryBase
// and annul the argument.
void transfer(DictionaryBase<IDLListType, T>&);
void transfer(DictionaryBase<IDLListType, T>& dict);
// Member operators
// Member Operators
//- Copy assigment
void operator=(const DictionaryBase&);
//- Find and return entry
@ -175,7 +176,7 @@ public:
}
// Ostream operator
// Ostream Operator
friend Ostream& operator<< <IDLListType, T>
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -23,9 +23,6 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Reads the data description and data portions of a DictionaryBase File.
\*---------------------------------------------------------------------------*/
#include "DictionaryBase.H"
@ -39,12 +36,7 @@ Foam::Ostream& Foam::operator<<
Ostream& os,
const DictionaryBase<IDLListType, T>& dict)
{
for
(
typename IDLListType::const_iterator iter = dict.begin();
iter != dict.end();
++iter
)
for (auto iter = dict.begin(); iter != dict.end(); ++iter)
{
os << *iter;
@ -56,7 +48,7 @@ Foam::Ostream& Foam::operator<<
<< "Can't write entry for DictionaryBase"
<< endl;
return os;
break;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2018 OpenFOAM Foundation
@ -339,7 +339,7 @@ Foam::simpleObjectRegistry& Foam::debug::debugObjects()
{
if (!debugObjectsPtr_)
{
debugObjectsPtr_ = new simpleObjectRegistry(1000);
debugObjectsPtr_ = new simpleObjectRegistry(128);
}
return *debugObjectsPtr_;
@ -350,7 +350,7 @@ Foam::simpleObjectRegistry& Foam::debug::infoObjects()
{
if (!infoObjectsPtr_)
{
infoObjectsPtr_ = new simpleObjectRegistry(100);
infoObjectsPtr_ = new simpleObjectRegistry(128);
}
return *infoObjectsPtr_;
@ -361,7 +361,7 @@ Foam::simpleObjectRegistry& Foam::debug::optimisationObjects()
{
if (!optimisationObjectsPtr_)
{
optimisationObjectsPtr_ = new simpleObjectRegistry(100);
optimisationObjectsPtr_ = new simpleObjectRegistry(128);
}
return *optimisationObjectsPtr_;
@ -372,7 +372,7 @@ Foam::simpleObjectRegistry& Foam::debug::dimensionSetObjects()
{
if (!dimensionSetObjectsPtr_)
{
dimensionSetObjectsPtr_ = new simpleObjectRegistry(100);
dimensionSetObjectsPtr_ = new simpleObjectRegistry(128);
}
return *dimensionSetObjectsPtr_;
@ -383,7 +383,7 @@ Foam::simpleObjectRegistry& Foam::debug::dimensionedConstantObjects()
{
if (!dimensionedConstantObjectsPtr_)
{
dimensionedConstantObjectsPtr_ = new simpleObjectRegistry(100);
dimensionedConstantObjectsPtr_ = new simpleObjectRegistry(128);
}
return *dimensionedConstantObjectsPtr_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2012-2016 OpenFOAM Foundation
@ -74,10 +74,10 @@ public:
// Constructors
//- Construct given initial table size
simpleObjectRegistry(const label nIoObjects = 128)
//- Construct with given or default (128) table capacity
explicit simpleObjectRegistry(const label size = 128)
:
Dictionary<simpleObjectRegistryEntry>(nIoObjects)
Dictionary<simpleObjectRegistryEntry>(size)
{}
};