/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2022-2024 OpenFOAM Foundation \\/ 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 . \*---------------------------------------------------------------------------*/ #include "HashList.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { template const Key HashList::nullKey = Key::null; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::HashList::HashList(const label size) : DynamicList>(size, Tuple2(nullKey, Type())) {} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // template inline Foam::label Foam::HashList::capacity() const { return DynamicList>::size(); } template void Foam::HashList::clear() { DynamicList>::operator= ( Tuple2(nullKey, Type()) ); } template void Foam::HashList::resizeAndClear(const label newSize) { DynamicList>::resize(newSize); clear(); } template bool Foam::HashList::insert(const Key& k, const Type& t) { DynamicList>& map = *this; const label n = map.size(); const unsigned h = Hash()(k); for (label i = 0; i < n; i ++) { const label hi = (h + i) % n; if (map[hi].first() == nullKey) { map[hi] = Tuple2(k, t); return true; } if (map[hi].first() == k) { return false; } } FatalErrorInFunction << "Hash list is full" << exit(FatalError); return false; } // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // template const Type& Foam::HashList::operator[](const Key& k) const { const DynamicList>& map = *this; const label n = map.size(); const unsigned h = Hash()(k); for (label i = 0; i < n; i ++) { const label hi = (h + i) % n; if (map[hi].first() == k) { return map[hi].second(); } } FatalErrorInFunction << "Hash list does not contain key \"" << k << "\"" << exit(FatalError); return NullObjectRef(); } // ************************************************************************* //