Line data Source code
1 : // SPDX-FileCopyrightText: 2024 PairInteraction Developers
2 : // SPDX-License-Identifier: LGPL-3.0-or-later
3 :
4 : #include "pairinteraction/utils/IndicesOfBlocks.hpp"
5 :
6 : namespace pairinteraction {
7 :
8 2595 : IndicesOfBlock::IndicesOfBlock(size_t start, size_t end) : start(start), end(end) {}
9 :
10 5150 : size_t IndicesOfBlock::size() const { return end - start; }
11 :
12 661 : IndicesOfBlocksCreator::IndicesOfBlocksCreator(std::initializer_list<size_t> boundaries)
13 1322 : : boundaries(boundaries) {}
14 :
15 1934 : void IndicesOfBlocksCreator::add(size_t boundary) { boundaries.insert(boundary); }
16 :
17 661 : std::vector<IndicesOfBlock> IndicesOfBlocksCreator::create() const {
18 661 : std::vector<IndicesOfBlock> blocks;
19 661 : if (boundaries.empty()) {
20 0 : return blocks;
21 : }
22 :
23 661 : auto it = boundaries.begin();
24 661 : size_t start = *it++;
25 :
26 3256 : while (it != boundaries.end()) {
27 2595 : blocks.emplace_back(start, *it);
28 2595 : start = *it++;
29 : }
30 :
31 661 : return blocks;
32 0 : }
33 :
34 0 : size_t IndicesOfBlocksCreator::size() const {
35 0 : return boundaries.empty() ? 0 : boundaries.size() - 1;
36 : }
37 : } // namespace pairinteraction
|