Coverage Report

Created: 2024-11-20 19:28

/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 <gen_cpp/Types_types.h>
21
#include <gen_cpp/types.pb.h>
22
#include <glog/logging.h>
23
24
#include <cstdlib>
25
26
#include "util/hash_util.hpp"
27
28
namespace doris {
29
30
132
size_t UniqueId::hash(size_t seed) const {
31
132
    return doris::HashUtil::hash(this, sizeof(*this), seed);
32
132
}
33
34
0
std::size_t hash_value(const doris::TUniqueId& id) {
35
0
    std::size_t seed = 0;
36
0
    HashUtil::hash_combine(seed, id.lo);
37
0
    HashUtil::hash_combine(seed, id.hi);
38
0
    return seed;
39
0
}
40
41
112
std::ostream& operator<<(std::ostream& os, const UniqueId& uid) {
42
112
    os << uid.to_string();
43
112
    return os;
44
112
}
45
46
700
std::string print_id(const TUniqueId& id) {
47
700
    std::stringstream out;
48
700
    out << std::hex << id.hi << "-" << id.lo;
49
700
    return out.str();
50
700
}
51
52
143
std::string print_id(const PUniqueId& id) {
53
143
    std::stringstream out;
54
143
    out << std::hex << id.hi() << "-" << id.lo();
55
143
    return out.str();
56
143
}
57
58
0
bool parse_id(const std::string& s, TUniqueId* id) {
59
0
    DCHECK(id != nullptr);
60
61
0
    const char* hi_part = s.c_str();
62
0
    char* colon = const_cast<char*>(strchr(hi_part, '-'));
63
64
0
    if (colon == nullptr) {
65
0
        return false;
66
0
    }
67
68
0
    const char* lo_part = colon + 1;
69
0
    *colon = '\0';
70
71
0
    char* error_hi = nullptr;
72
0
    char* error_lo = nullptr;
73
0
    id->hi = strtoul(hi_part, &error_hi, 16);
74
0
    id->lo = strtoul(lo_part, &error_lo, 16);
75
76
0
    bool valid = *error_hi == '\0' && *error_lo == '\0';
77
0
    *colon = ':';
78
0
    return valid;
79
0
}
80
81
} // namespace doris