Coverage Report

Created: 2025-06-25 21:34

/root/doris/be/src/util/uid_util.cpp
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/uid_util.h"
19
20
#include <fmt/compile.h>
21
#include <gen_cpp/Types_types.h>
22
#include <gen_cpp/types.pb.h>
23
#include <glog/logging.h>
24
25
#include <cstdlib>
26
27
#include "util/hash_util.hpp"
28
29
namespace doris {
30
31
951
size_t UniqueId::hash(size_t seed) const {
32
951
    return doris::HashUtil::hash(this, sizeof(*this), seed);
33
951
}
34
35
1
std::size_t hash_value(const doris::TUniqueId& id) {
36
1
    std::size_t seed = 0;
37
1
    HashUtil::hash_combine(seed, id.lo);
38
1
    HashUtil::hash_combine(seed, id.hi);
39
1
    return seed;
40
1
}
41
42
102
std::ostream& operator<<(std::ostream& os, const UniqueId& uid) {
43
102
    os << uid.to_string();
44
102
    return os;
45
102
}
46
47
0
std::string print_id(const UniqueId& id) {
48
0
    return id.to_string();
49
0
}
50
51
1.24M
std::string print_id(const TUniqueId& id) {
52
1.24M
    return fmt::format(FMT_COMPILE("{:x}-{:x}"), static_cast<uint64_t>(id.hi),
53
1.24M
                       static_cast<uint64_t>(id.lo));
54
1.24M
}
55
56
1.06k
std::string print_id(const PUniqueId& id) {
57
1.06k
    return fmt::format(FMT_COMPILE("{:x}-{:x}"), static_cast<uint64_t>(id.hi()),
58
1.06k
                       static_cast<uint64_t>(id.lo()));
59
1.06k
}
60
61
0
bool parse_id(const std::string& s, TUniqueId* id) {
62
0
    DCHECK(id != nullptr);
63
64
0
    const char* hi_part = s.c_str();
65
0
    char* colon = const_cast<char*>(strchr(hi_part, '-'));
66
67
0
    if (colon == nullptr) {
68
0
        return false;
69
0
    }
70
71
0
    const char* lo_part = colon + 1;
72
0
    *colon = '\0';
73
74
0
    char* error_hi = nullptr;
75
0
    char* error_lo = nullptr;
76
0
    id->hi = strtoul(hi_part, &error_hi, 16);
77
0
    id->lo = strtoul(lo_part, &error_lo, 16);
78
79
0
    bool valid = *error_hi == '\0' && *error_lo == '\0';
80
0
    *colon = ':';
81
0
    return valid;
82
0
}
83
84
} // namespace doris