Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <ostream>
#include <string>
#include <string_view>
#include <tuple>
 
#include "core/common/common.h"
#include "core/common/hash_combine.h"
#include "core/common/status.h"
#include "core/common/string_utils.h"
#include "core/common/parse_string.h"
 
namespace onnxruntime {
 
template <typename StringType>
struct BasicOpIdentifier {
  StringType domain;
  StringType op_type;
  int since_version;
 
  // comparison
 
  friend constexpr bool operator<(const BasicOpIdentifier& lhs,
                                  const BasicOpIdentifier& rhs) {
    return lhs.Tied() < rhs.Tied();
  }
 
  friend constexpr bool operator==(const BasicOpIdentifier& lhs,
                                   const BasicOpIdentifier& rhs) {
    return lhs.Tied() == rhs.Tied();
  }
 
  // hash computation
 
  size_t GetHash() const {
    size_t h = std::hash<StringType>{}(domain);
    HashCombine(op_type, h);
    HashCombine(since_version, h);
    return h;
  }
 
  // string conversion
 
  std::string ToString() const {
    return MakeString(domain, kStringRepresentationDelimiter,
                      op_type, kStringRepresentationDelimiter,
                      since_version);
  }
 
  static Status LoadFromString(std::string_view op_id_str, BasicOpIdentifier& op_id) {
    const auto components = utils::SplitString(op_id_str, kStringRepresentationDelimiter, true);
    ORT_RETURN_IF_NOT(components.size() == 3, "Invalid OpIdentifier string: ", op_id_str);
    int since_version{};
    ORT_RETURN_IF_NOT(TryParseStringWithClassicLocale(components[2], since_version),
                      "Failed to parse since_version from ", components[2]);
    op_id = BasicOpIdentifier{StringType{components[0]}, StringType{components[1]}, since_version};
    return Status::OK();
  }
 
  friend std::ostream& operator<<(std::ostream& os, const BasicOpIdentifier& op_id) {
    os << op_id.ToString();
    return os;
  }
 
 private:
  constexpr auto Tied() const {
    return std::tie(domain, op_type, since_version);
  }
 
  static constexpr std::string_view kStringRepresentationDelimiter = ":";
};
 
using OpIdentifier = BasicOpIdentifier<std::string>;
 
// An op identifier that uses std::string_view to refer to domain and op type values.
// IMPORTANT: Be sure that the underlying strings remain valid for the lifetime of the op identifier.
using OpIdentifierWithStringViews = BasicOpIdentifier<std::string_view>;
 
}  // namespace onnxruntime
 
// add std::hash specializations
namespace std {
template <>
struct hash<onnxruntime::OpIdentifier> {
  size_t operator()(const onnxruntime::OpIdentifier& v) const {
    return v.GetHash();
  }
};
 
template <>
struct hash<onnxruntime::OpIdentifierWithStringViews> {
  size_t operator()(const onnxruntime::OpIdentifierWithStringViews& v) const {
    return v.GetHash();
  }
};
}  // namespace std