/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 "PackedList.H" #include "labelRange.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::PackedList::PackedList ( const PackedList& list, const labelUList& addr ) : PackedList(addr.size()) { const label len = addr.size(); for (label i = 0; i < len; ++i) { set(i, list.get(addr[i])); } } template template Foam::PackedList::PackedList ( const PackedList& list, const IndirectListBase& addr ) : PackedList(addr.size()) { const label len = addr.size(); for (label i = 0; i < len; ++i) { set(i, list.get(addr[i])); } } template Foam::PackedList::PackedList ( const PackedList& list, const labelRange& range ) : PackedList(range.size()) { label pos = range.start(); const label len = range.size(); for (label i = 0; i < len; ++i) { set(i, list.get(pos)); ++pos; } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template bool Foam::PackedList::uniform() const { // Trivial cases if (empty()) { return false; } else if (size() == 1) { return true; } // The value of the first element for testing const unsigned int val = get(0); const label nblocks = num_blocks(size()); bool identical = true; if (!val) { // Zero value: can just check block content directly for (label blocki = 0; identical && blocki < nblocks; ++blocki) { identical = !blocks_[blocki]; } return identical; } else if (nblocks > 1) { // Check all blocks that are completely occupied: (nblocks-1) const unsigned int blockval = BitOps::repeat_value(val); for (label blocki = 0; identical && blocki < (nblocks-1); ++blocki) { identical = (blocks_[blocki] == blockval); } } // Partial block: check manually for ( label elemi = elem_per_block*(nblocks-1); identical && elemi < size(); ++elemi ) { identical = (val == get(elemi)); } return identical; } template bool Foam::PackedList::equal(const PackedList& other) const { if (size() != other.size()) { return false; } const label nblocks = num_blocks(size()); const auto& rhs = other.blocks_; for (label blocki = 0; blocki < nblocks; ++blocki) { if (blocks_[blocki] != rhs[blocki]) { return false; } } return true; } template Foam::labelList Foam::PackedList::values() const { return this->unpack