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

PeterCDMcLean / BitLib / 14987214130

13 May 2025 03:02AM UTC coverage: 49.385% (-46.9%) from 96.333%
14987214130

Pull #7

github

web-flow
Merge aad228108 into 09dd4e61e
Pull Request #7: Add github workflow targets for warnings

5155 of 10638 branches covered (48.46%)

Branch coverage included in aggregate %.

39 of 70 new or added lines in 1 file covered. (55.71%)

128 existing lines in 10 files now uncovered.

5325 of 10583 relevant lines covered (50.32%)

3238286.52 hits per line

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

70.3
/include/bitlib/bit-algorithms/equal.hpp
1
// ================================= EQUAL =================================== //
2
// Project:     The Experimental Bit Algorithms Library
3
// Name:        equal.hpp
4
// Contributor: Bryce Kille [2019]
5
// License:     BSD 3-Clause License
6
// ========================================================================== //
7
#ifndef _EQUAL_HPP_INCLUDED
8
#define _EQUAL_HPP_INCLUDED
9
// ========================================================================== //
10

11

12

13
// ================================ PREAMBLE ================================ //
14
// C++ standard library
15
#include <type_traits>
16
#include <math.h>
17
// Project sources
18
#include "bitlib/bit-iterator/bit.hpp"
19
// Third-party libraries
20
// Miscellaneous
21
namespace bit {
22
// ========================================================================== //
23

24

25

26
// ---------------------------- Equal Algorithms ----------------------------- //
27

28
// Status: Does not work for Input/Output iterators due to distance call
29
template <class RandomAccessIt1, class RandomAccessIt2>
30
constexpr bool equal(
31
        bit_iterator<RandomAccessIt1> first,
32
        bit_iterator<RandomAccessIt1> last,
33
        bit_iterator<RandomAccessIt2> d_first
34
)
35
{
1,034✔
36
    // Types and constants
37
    using dst_word_type = typename bit_iterator<RandomAccessIt2>::word_type;
1,034✔
38
    using src_word_type = typename bit_iterator<RandomAccessIt1>::word_type;
1,034✔
39
    using word_type = dst_word_type;
1,034✔
40
    using size_type = typename bit_iterator<RandomAccessIt2>::size_type;
1,034✔
41
    constexpr size_type digits = binary_digits<word_type>::value;
1,034✔
42

43
    // Assertions
44
    _assert_range_viability(first, last);
1,034✔
45
    static_assert(::std::is_same<dst_word_type, src_word_type>::value, "Underlying word types must be equal");
1,034✔
46
    if (first == last) return true;
1,034!
47

48
    // Initialization
49
    const bool is_d_first_aligned = d_first.position() == 0;
964✔
50
    size_type total_bits_to_check = distance(first, last);
964✔
51
    size_type remaining_bits_to_check = total_bits_to_check;
964✔
52
    auto it = d_first.base();
964✔
53

54
    // d_first is not aligned.
55
    if (!is_d_first_aligned) {
964!
56
        const size_type partial_bits_to_check = ::std::min(
762✔
57
                remaining_bits_to_check,
762✔
58
                digits - d_first.position());
762✔
59
        const word_type mask = static_cast<word_type>(
762✔
60
                (static_cast<word_type>(1) << partial_bits_to_check) - 1
762✔
61
        ) << d_first.position();
762✔
62
        const word_type comp = static_cast<word_type>(
762✔
63
              get_word<word_type>(first, partial_bits_to_check)
762✔
64
                << d_first.position());
762✔
65
        if ((mask & *it) != (mask & comp)) { return false; }
762!
66
        remaining_bits_to_check -= partial_bits_to_check;
762✔
67
        advance(first, partial_bits_to_check);
762✔
68
        it++;
762✔
69
    }
762✔
70

71
    if (remaining_bits_to_check > 0) {
964!
72
        const bool is_first_aligned = first.position() == 0;
696✔
73
        // d_first will be aligned at this point
74
        if (is_first_aligned && remaining_bits_to_check >= digits) {
696!
75
            auto N = ::std::distance(first.base(), last.base());
453✔
76
            bool found_mismatch = !::std::equal(first.base(), last.base(), it);
453✔
77
            if (found_mismatch) {return false;}
453!
78
            it += N;
452✔
79
            first += digits * N;
452✔
80
            remaining_bits_to_check -= digits * N;
452✔
81
        } else {
452✔
82
            // TODO benchmark if its faster to ::std::check the entire range then shift
83
            while (remaining_bits_to_check >= digits) {
243!
84
                if (*it != get_word<word_type>(first, digits)) {return false;}
×
85
                remaining_bits_to_check -= digits;
×
86
                it++;
×
87
                advance(first, digits);
×
UNCOV
88
            }
×
89
        }
243✔
90
        if (remaining_bits_to_check > 0) {
695✔
91
            const word_type mask = static_cast<word_type>(
671✔
92
                    (static_cast<word_type>(1) << remaining_bits_to_check) - 1
671✔
93
            );
671✔
94
            const word_type comp = get_word<word_type>(first, remaining_bits_to_check);
671✔
95
            if ((mask & *it) != (mask & comp)) { return false; }
671!
96
        }
671✔
97
    }
695✔
98
    return true;
961✔
99
}
964✔
100
// -------------------------------------------------------------------------- //
101

102

103

104
// ========================================================================== //
105
} // namespace bit
106
#endif // _EQUAL_HPP_INCLUDED
107
// ========================================================================== //
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