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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

72.97
/libs/full/naming_base/src/gid_type.cpp
1
//  Copyright (c) 2007-2025 Hartmut Kaiser
2
//  Copyright (c) 2011      Bryce Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/assert.hpp>
9
#include <hpx/modules/format.hpp>
10
#include <hpx/modules/logging.hpp>
11
#include <hpx/modules/serialization.hpp>
12
#include <hpx/modules/util.hpp>
13
#include <hpx/naming_base/gid_type.hpp>
14

15
#include <cstdint>
16
#include <functional>
17
#include <memory>
18
#include <mutex>
19
#include <ostream>
20
#include <string>
21
#include <utility>
22

23
///////////////////////////////////////////////////////////////////////////////
24
namespace hpx::naming {
25

26
    ///////////////////////////////////////////////////////////////////////////
27
    bool operator<(gid_type const& lhs, gid_type const& rhs) noexcept
28
    {
39,041✔
29
        auto const lhs_msb = static_cast<std::int64_t>(
30
            detail::strip_internal_bits_from_gid(lhs.id_msb_));
31
        auto const rhs_msb = static_cast<std::int64_t>(
39,041✔
32
            detail::strip_internal_bits_from_gid(rhs.id_msb_));
33

39,041✔
34
        if (lhs_msb < rhs_msb)
35
        {
39,041✔
36
            return true;
37
        }
38
        if (lhs_msb > rhs_msb)
39
        {
35,292✔
40
            return false;
41
        }
42
        return lhs.id_lsb_ < rhs.id_lsb_;
43
    }
35,160✔
44

45
    bool operator<=(gid_type const& lhs, gid_type const& rhs) noexcept
46
    {
125✔
47
        auto const lhs_msb = static_cast<std::int64_t>(
48
            detail::strip_internal_bits_from_gid(lhs.id_msb_));
49
        auto const rhs_msb = static_cast<std::int64_t>(
125✔
50
            detail::strip_internal_bits_from_gid(rhs.id_msb_));
51

125✔
52
        if (lhs_msb < rhs_msb)
53
        {
125✔
54
            return true;
55
        }
56
        if (lhs_msb > rhs_msb)
57
        {
61✔
58
            return false;
59
        }
60
        return lhs.id_lsb_ <= rhs.id_lsb_;
61
    }
61✔
62

63
    ///////////////////////////////////////////////////////////////////////////
64
    gid_type operator+(gid_type const& lhs, gid_type const& rhs) noexcept
65
    {
2,695✔
66
        std::uint64_t const lsb = lhs.id_lsb_ + rhs.id_lsb_;
67
        std::uint64_t msb = lhs.id_msb_ + rhs.id_msb_;
2,695✔
68

2,695✔
69
#if defined(HPX_DEBUG)
70
        // make sure we're using the operator+ in proper contexts only
71
        std::uint64_t const lhs_internal_bits =
72
            detail::get_internal_bits(lhs.id_msb_);
73

74
        std::uint64_t const msb_test =
75
            detail::strip_internal_bits_and_component_type_from_gid(
76
                lhs.id_msb_) +
77
            detail::strip_internal_bits_and_locality_from_gid(rhs.id_msb_);
78

79
        HPX_ASSERT(msb == (msb_test | lhs_internal_bits));
80
#endif
81

82
        if (lsb < lhs.id_lsb_ || lsb < rhs.id_lsb_)
83
            ++msb;
2,695✔
84

×
85
        return gid_type(msb, lsb);
86
    }
2,695✔
87

88
    gid_type operator-(gid_type const& lhs, gid_type const& rhs) noexcept
89
    {
12✔
90
        std::uint64_t const lsb = lhs.id_lsb_ - rhs.id_lsb_;
91
        std::uint64_t msb = lhs.id_msb_ - rhs.id_msb_;
12✔
92

12✔
93
        if (lsb > lhs.id_lsb_)
94
            --msb;
12✔
95

×
96
        return gid_type(msb, lsb);
97
    }
12✔
98

99
    std::string gid_type::to_string() const
100
    {
×
101
        return hpx::util::format("{:016llx}{:016llx}", id_msb_, id_lsb_);
102
    }
×
103

104
    std::ostream& operator<<(std::ostream& os, gid_type const& id)
105
    {
3✔
106
        hpx::util::ios_flags_saver ifs(os);
107
        if (id != naming::invalid_gid)
3✔
108
        {
109
            hpx::util::format_to(
110
                os, "{{{:016llx}, {:016llx}}}", id.id_msb_, id.id_lsb_);
3✔
111
        }
3✔
112
        else
113
        {
114
            os << "{invalid}";
115
        }
×
116
        return os;
117
    }
3✔
118

119
    ///////////////////////////////////////////////////////////////////////////
120
    void save(
121
        serialization::output_archive& ar, gid_type const& gid, unsigned int)
×
122
    {
123
        ar << gid.id_msb_ << gid.id_lsb_;
124
    }
125

×
126
    void load(serialization::input_archive& ar, gid_type& gid, unsigned int)
127
    {
×
128
        ar >> gid.id_msb_ >> gid.id_lsb_;
129

130
        // strip lock-bit upon receive
131
        gid.id_msb_ &= ~gid_type::is_locked_mask;
132
    }
×
133
}    // namespace hpx::naming
×
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