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

PeterCDMcLean / BitLib / 16544577083

26 Jul 2025 10:39PM UTC coverage: 76.997% (-1.5%) from 78.485%
16544577083

Pull #18

github

web-flow
Merge 4bac8f49d into 079daa142
Pull Request #18: From string

3414 of 5100 branches covered (66.94%)

Branch coverage included in aggregate %.

264 of 313 new or added lines in 12 files covered. (84.35%)

30 existing lines in 2 files now uncovered.

2494 of 2573 relevant lines covered (96.93%)

31115123.0 hits per line

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

69.23
/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 <
19
    bool forward,
20
    bool initial_sub_word,
21
    typename RandomAccessItIn,
22
    typename RandomAccessItOut,
23
    typename T,
24
    typename BinaryOperation,
25
    typename BinaryOperationSubword>
26
  requires(
27
      (std::is_same_v<std::remove_cvref_t<std::iter_value_t<RandomAccessItIn>>,
28
                      std::remove_cvref_t<std::iter_value_t<RandomAccessItOut>>>))
29
constexpr auto transform_accumulate(
6✔
30
    bit_iterator<RandomAccessItIn> first,
31
    bit_iterator<RandomAccessItIn> last,
32
    bit_iterator<RandomAccessItOut> d_first,
33
    bit_iterator<RandomAccessItOut> d_last,
34
    T acc,
35
    BinaryOperation binary_op,
36
    BinaryOperationSubword binary_op_subword) {
6✔
37
  using word_type = typename bit_iterator<RandomAccessItOut>::word_type;
6✔
38
  using size_type = typename bit_iterator<RandomAccessItOut>::size_type;
6✔
39
  constexpr size_type digits = bitsof<word_type>();
12✔
40

41
  size_type total_bits_to_op = distance(first, last);
12✔
42

43
  RandomAccessItOut d_it;
12✔
44
  if constexpr (forward) {
45
    d_it = d_first.base();
46
  } else {
6✔
47
    d_it = d_last.base();
12✔
48
  }
6✔
49

50
  if constexpr (forward) {
51
    if (d_first.position() != 0) {
52
      size_type partial_bits_to_op = ::std::min(
53
          total_bits_to_op,
54
          digits - d_first.position());
55
      if (partial_bits_to_op != 0) {
56
        word_type word;
57
        std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(first, partial_bits_to_op), partial_bits_to_op);
58
        *d_it = _bitblend(
59
            *d_it,
60
            word,
61
            static_cast<word_type>(d_first.position()),
62
            static_cast<word_type>(partial_bits_to_op));
63
        total_bits_to_op -= partial_bits_to_op;
64
        advance(first, partial_bits_to_op);
65
        advance(d_it, 1);
66
      }
67
    }
68
  } else {
6✔
69
    if (d_last.position() != 0) {
12!
70
      size_type partial_bits_to_op = ::std::min(
12✔
71
          total_bits_to_op,
6✔
72
          d_last.position());
18✔
73
      if (partial_bits_to_op != 0) {
12!
74
        advance(last, -partial_bits_to_op);
12✔
75
        word_type word;
12✔
76
        std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(last, partial_bits_to_op), partial_bits_to_op);
12✔
77
        *d_it = _bitblend(
12✔
78
            *d_it,
6✔
79
            word,
6✔
80
            static_cast<word_type>(d_first.position()),
12✔
81
            static_cast<word_type>(partial_bits_to_op));
6✔
82
        total_bits_to_op -= partial_bits_to_op;
12✔
83
      }
6✔
84
    }
6✔
85
  }
6✔
86

87

88
  const size_type whole_words_to_op = total_bits_to_op / digits;
12✔
89
  const size_type remaining_bits_to_op = total_bits_to_op % digits;
12✔
90

91
  for (size_t i = 0; i < whole_words_to_op; i ++) {
12!
92
    if constexpr (forward) {
93
      word_type word;
94
      std::tie(word, acc) = binary_op(std::move(acc), get_word<word_type>(first));
95
      *d_it = word;
96
      advance(first, digits);
97
      std::advance(d_it, 1);
NEW
98
    } else {
NEW
99
      advance(last, -digits);
×
NEW
100
      std::advance(d_it, -1);
NEW
101
      word_type word;
×
NEW
102
      std::tie(word, acc) = binary_op(std::move(acc), get_word<word_type>(last));
×
NEW
103
      *d_it = word;
×
NEW
104
    }
NEW
105
  }
106
  if (remaining_bits_to_op > 0) {
12!
107
    if constexpr (forward) {
108
      word_type word;
109
      std::tie(word, acc) = binary_op_subword(std::move(acc), get_masked_word<word_type>(first, remaining_bits_to_op), remaining_bits_to_op);
110
      *d_it = _bitblend(
111
          *d_it,
112
          word,
113
          0,
114
          remaining_bits_to_op);
115

NEW
116
    } else {
NEW
117
      advance(last, -remaining_bits_to_op);
×
NEW
118
      std::advance(d_it, -1);
NEW
119
      word_type word;
×
NEW
120
      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
121
      *d_it = _bitblend(
×
NEW
122
          *d_it,
NEW
123
          word,
NEW
124
          0,
NEW
125
          remaining_bits_to_op);
NEW
126
    }
NEW
127
  }
128

129
  return acc;
18✔
130
}
6✔
131

132
template <
133
    typename RandomAccessItIn,
134
    typename RandomAccessItOut,
135
    typename T,
136
    typename BinaryOperation,
137
    typename BinaryOperationSubword>
138
  requires(
139
      (std::is_same_v<std::remove_cvref_t<std::iter_value_t<RandomAccessItIn>>,
140
                      std::remove_cvref_t<std::iter_value_t<RandomAccessItOut>>>))
141
constexpr auto transform_accumulate_backward(
6✔
142
    const bit_iterator<RandomAccessItIn>& first,
143
    const bit_iterator<RandomAccessItIn>& last,
144
    const bit_iterator<RandomAccessItOut>& d_first,
145
    const bit_iterator<RandomAccessItOut>& d_last,
146
    const T& acc,
147
    BinaryOperation binary_op,
148
    BinaryOperationSubword binary_op_subword) {
6✔
149
  return transform_accumulate<false, true>(first, last, d_first, d_last, acc, binary_op, binary_op_subword);
18✔
150
}
6✔
151

152
} // namespace bit
153

154
#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

© 2025 Coveralls, Inc