• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adc-connect / adcc / 5362537629

pending completion
5362537629

push

github

mfherbst
Bump version: 0.15.16 → 0.15.17

1487 of 2318 branches covered (64.15%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

7130 of 9470 relevant lines covered (75.29%)

191956.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
/libadcc/MoSpaces/construct_blocks.cc
1
//
2
// Copyright (C) 2019 by the adcc authors
3
//
4
// This file is part of adcc.
5
//
6
// adcc is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published
8
// by the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
10
//
11
// adcc is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with adcc. If not, see <http://www.gnu.org/licenses/>.
18
//
19

20
#include "construct_blocks.hh"
21
#include "../exceptions.hh"
22

23
namespace libadcc {
24

25
std::vector<size_t> construct_blocks(std::vector<size_t> block_starts_crude,
20,304✔
26
                                     size_t length, size_t max_block_size) {
27
  std::vector<size_t> ret;
20,304✔
28

29
  // Lambda to insert extra block starts into ret. It gets the last position of a block
30
  // start and the next planned one and checks whether this is so large such that extra
31
  // starts need to be inserted. If that is the case these are inserted to ret.
32
  auto insert_extra_starts = [](std::vector<size_t>& ret, size_t last_start,
39,456✔
33
                                size_t next_start, size_t max_block_size) {
34
    const size_t len = next_start - last_start;
39,456✔
35
    if (len > max_block_size) {
39,456✔
36
      // Split into this number of blocks:
37
      const size_t n_blocks = (len + max_block_size - 1) / max_block_size;
960✔
38

39
      // The first few blocks might need to be a little larger to
40
      // make sure to completely tile the length len.
41
      // The block size of the small blocks
42
      const size_t block_size = len / n_blocks;
960✔
43

44
      // The remainder gives the number of "large blocks" we need.
45
      const size_t n_large_blocks = len % n_blocks;
960✔
46

47
      // The current position of block starts
48
      size_t pos = last_start;
960✔
49
      for (size_t ib = 0; ib < n_large_blocks; ++ib) {
1,000✔
50
        if (ib != 0) ret.push_back(pos);
40✔
51
        pos += block_size + 1;
40✔
52
      }
53
      for (size_t ib = n_large_blocks; ib < n_blocks; ++ib) {
3,392✔
54
        if (ib != 0) ret.push_back(pos);
2,432✔
55
        pos += block_size;
2,432✔
56
      }
57
      if (pos != next_start) {
960✔
58
        throw runtime_error("Internal error: Block tiling failed.");
×
59
      }
60
    }
61
    return next_start;
39,456✔
62
  };
63

64
  // Make sure at least a block start at 0 is in the block_starts_crude
65
  if (block_starts_crude.empty()) {
20,304✔
66
    block_starts_crude.push_back(0);
×
67
  }
68
  size_t last_start = block_starts_crude.front();
20,304✔
69
  ret.push_back(last_start);
20,304✔
70
  for (auto it = block_starts_crude.begin() + 1; it != block_starts_crude.end(); ++it) {
39,456✔
71
    last_start = insert_extra_starts(ret, last_start, *it, max_block_size);
19,152✔
72
    ret.push_back(*it);
19,152✔
73
  }
74
  insert_extra_starts(ret, last_start, length, max_block_size);
20,304✔
75
  return ret;
40,608✔
76
}
×
77

78
}  // namespace libadcc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc