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

PeterCDMcLean / BitLib / 16535147226

26 Jul 2025 02:33AM UTC coverage: 77.05% (-1.4%) from 78.485%
16535147226

Pull #18

github

web-flow
Merge 3dbf7bd55 into 079daa142
Pull Request #18: From string

3406 of 5080 branches covered (67.05%)

Branch coverage included in aggregate %.

248 of 295 new or added lines in 12 files covered. (84.07%)

30 existing lines in 2 files now uncovered.

2476 of 2554 relevant lines covered (96.95%)

31346596.33 hits per line

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

71.43
/include/bitlib/bit-algorithms/transform_accumulate.hpp
1
// ================================= array_REF =================================== //
2
// Project:     The Experimental Bit Algorithms Library
3
// \file        accumulate.hpp
4
// Description: Implementation of accumulate
5
// Creator:     Vincent Reverdy
6
// Contributor: Peter McLean [2025]
7
// License:     BSD 3-Clause License
8
// ========================================================================== //
9

10
#ifndef _BIT_TRANSFORM_ACCUMULATE_HPP_INCLUDED
11
#define _BIT_TRANSFORM_ACCUMULATE_HPP_INCLUDED
12

13
#include "bitlib/bit-iterator/bit_iterator.hpp"
14
#include "bitlib/bit-iterator/bit_details.hpp"
15

16
namespace bit {
17

18
template <bool forward, bool initial_sub_word, typename RandomAccessIt, typename T, typename BinaryOperation, typename BinaryOperationSubword>
19
constexpr auto transform_accumulate(
3✔
20
    bit_iterator<RandomAccessIt> first,
21
    bit_iterator<RandomAccessIt> last,
22
    bit_iterator<RandomAccessIt> d_first,
23
    bit_iterator<RandomAccessIt> d_last,
24
    T acc,
25
    BinaryOperation binary_op,
26
    BinaryOperationSubword binary_op_subword) {
3✔
27
  using word_type = typename bit_iterator<RandomAccessIt>::word_type;
3✔
28
  using size_type = typename bit_iterator<RandomAccessIt>::size_type;
3✔
29
  constexpr size_type digits = bitsof<word_type>();
6✔
30

31
  size_type total_bits_to_op = distance(first, last);
6✔
32

33
  RandomAccessIt d_it;
6✔
34
  if constexpr (forward) {
35
    d_it = d_first.base();
36
  } else {
3✔
37
    d_it = d_last.base();
6✔
38
  }
3✔
39

40
  if constexpr (forward) {
41
    if (d_first.position() != 0) {
42
      size_type partial_bits_to_op = ::std::min(
43
          total_bits_to_op,
44
          digits - d_first.position());
45
      if (partial_bits_to_op != 0) {
46
        word_type word;
47
        std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(first, partial_bits_to_op), partial_bits_to_op);
48
        *d_it = _bitblend(
49
            *d_it,
50
            word,
51
            static_cast<word_type>(d_first.position()),
52
            static_cast<word_type>(partial_bits_to_op));
53
        total_bits_to_op -= partial_bits_to_op;
54
        advance(first, partial_bits_to_op);
55
        advance(d_it, 1);
56
      }
57
    }
58
  } else {
3✔
59
    if (d_last.position() != 0) {
6!
60
      size_type partial_bits_to_op = ::std::min(
6✔
61
          total_bits_to_op,
3✔
62
          d_last.position());
9✔
63
      if (partial_bits_to_op != 0) {
6!
64
        advance(last, -partial_bits_to_op);
6✔
65
        word_type word;
6✔
66
        std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(last, partial_bits_to_op), partial_bits_to_op);
6✔
67
        *d_it = _bitblend(
6✔
68
            *d_it,
3✔
69
            word,
3✔
70
            static_cast<word_type>(d_first.position()),
6✔
71
            static_cast<word_type>(partial_bits_to_op));
3✔
72
        total_bits_to_op -= partial_bits_to_op;
6✔
73
      }
3✔
74
    }
3✔
75
  }
3✔
76

77

78
  const size_type whole_words_to_op = total_bits_to_op / digits;
6✔
79
  const size_type remaining_bits_to_op = total_bits_to_op % digits;
6✔
80

81
  for (size_t i = 0; i < whole_words_to_op; i ++) {
6!
82
    if constexpr (forward) {
83
      word_type word;
84
      std::tie(word, acc) = binary_op(std::move(acc), get_word<word_type>(first));
85
      *d_it = word;
86
      advance(first, digits);
87
      std::advance(d_it, 1);
NEW
88
    } else {
NEW
89
      advance(last, -digits);
×
NEW
90
      std::advance(d_it, -1);
NEW
91
      word_type word;
×
NEW
92
      std::tie(word, acc) = binary_op(std::move(acc), get_word<word_type>(last));
×
NEW
93
      *d_it = word;
×
NEW
94
    }
NEW
95
  }
96
  if (remaining_bits_to_op > 0) {
6!
97
    if constexpr (forward) {
98
      word_type word;
99
      std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(first, remaining_bits_to_op), remaining_bits_to_op);
100
      *d_it = _bitblend(
101
          *d_it,
102
          word,
103
          0,
104
          remaining_bits_to_op);
105

NEW
106
    } else {
NEW
107
      advance(last, -remaining_bits_to_op);
×
NEW
108
      std::advance(d_it, -1);
NEW
109
      word_type word;
×
NEW
110
      std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(last, remaining_bits_to_op), remaining_bits_to_op);
×
NEW
111
      *d_it = _bitblend(
×
NEW
112
          *d_it,
NEW
113
          word,
NEW
114
          0,
NEW
115
          remaining_bits_to_op);
NEW
116
    }
NEW
117
  }
118

119
  return acc;
9✔
120
}
3✔
121

122
template <typename RandomAccessIt, typename T, typename BinaryOperation, typename BinaryOperationSubword>
123
constexpr auto transform_accumulate_backward(
3✔
124
    const bit_iterator<RandomAccessIt>& first,
125
    const bit_iterator<RandomAccessIt>& last,
126
    const bit_iterator<RandomAccessIt>& d_first,
127
    const bit_iterator<RandomAccessIt>& d_last,
128
    const T& acc,
129
    BinaryOperation binary_op,
130
    BinaryOperationSubword binary_op_subword) {
3✔
131
  return transform_accumulate<false, true>(first, last, d_first, d_last, acc, binary_op, binary_op_subword);
9✔
132
}
3✔
133

134
} // namespace bit
135

136
#endif // _BIT_TRANSFORM_ACCUMULATE_HPP_INCLUDED
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