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

arangodb / velocypack / 3998645281

pending completion
3998645281

Pull #148

github

GitHub
Merge b1e3c924b into 5a28b6413
Pull Request #148: use separate namespace for xxh functions

0 of 5107 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Compare.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
/// DISCLAIMER
3
///
4
/// Copyright 2014-2020 ArangoDB GmbH, Cologne, Germany
5
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6
///
7
/// Licensed under the Apache License, Version 2.0 (the "License");
8
/// you may not use this file except in compliance with the License.
9
/// You may obtain a copy of the License at
10
///
11
///     http://www.apache.org/licenses/LICENSE-2.0
12
///
13
/// Unless required by applicable law or agreed to in writing, software
14
/// distributed under the License is distributed on an "AS IS" BASIS,
15
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
/// See the License for the specific language governing permissions and
17
/// limitations under the License.
18
///
19
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20
///
21
/// @author Max Neunhoeffer
22
/// @author Jan Steemann
23
////////////////////////////////////////////////////////////////////////////////
24

25
#include "velocypack/Compare.h"
26
#include "velocypack/Collection.h"
27
#include "velocypack/Exception.h"
28
#include "velocypack/Iterator.h"
29
#include "velocypack/Options.h"
30
#include "velocypack/Slice.h"
31
#include "velocypack/ValueType.h"
32

33
#include <set>
34

35
using namespace arangodb::velocypack;
36

37
bool BinaryCompare::equals(Slice lhs, Slice rhs) {
×
38
  return lhs.binaryEquals(rhs);
×
39
}
40

41
size_t BinaryCompare::Hash::operator()(
×
42
    arangodb::velocypack::Slice const& slice) const {
43
  return static_cast<size_t>(slice.hash());
×
44
}
45

46
bool BinaryCompare::Equal::operator()(
×
47
    arangodb::velocypack::Slice const& lhs,
48
    arangodb::velocypack::Slice const& rhs) const {
49
  return lhs.binaryEquals(rhs);
×
50
}
51

52
bool NormalizedCompare::equalsNumbers(Slice lhs, Slice rhs) {
×
53
  auto lhsType = lhs.type();
×
54
  if (lhsType == rhs.type()) {
×
55
    // both types are equal
56
    if (lhsType == ValueType::Int || lhsType == ValueType::SmallInt) {
×
57
      // use exact comparisons. no need to cast to double
58
      return (lhs.getIntUnchecked() == rhs.getIntUnchecked());
×
59
    }
60

61
    if (lhsType == ValueType::UInt) {
×
62
      // use exact comparisons. no need to cast to double
63
      return (lhs.getUIntUnchecked() == rhs.getUIntUnchecked());
×
64
    }
65
    // fallthrough to double comparison
66
  }
67

68
  return (lhs.getNumericValue<double>() == rhs.getNumericValue<double>());
×
69
}
70

71
bool NormalizedCompare::equalsStrings(Slice lhs, Slice rhs) {
×
72
  ValueLength nl;
73
  char const* left = lhs.getString(nl);
×
74
  VELOCYPACK_ASSERT(left != nullptr);
×
75
  ValueLength nr;
76
  char const* right = rhs.getString(nr);
×
77
  VELOCYPACK_ASSERT(right != nullptr);
×
78
  return (nl == nr && (std::memcmp(left, right, nl) == 0));
×
79
}
80

81
bool NormalizedCompare::equals(Slice lhs, Slice rhs) {
×
82
  lhs = lhs.resolveExternals();
×
83
  rhs = rhs.resolveExternals();
×
84
  ValueType lhsType = valueTypeGroup(lhs.type());
×
85
  ValueType rhsType = valueTypeGroup(rhs.type());
×
86

87
  if (lhsType != rhsType) {
×
88
    // unequal types => not equal
89
    return false;
×
90
  }
91

92
  switch (lhsType) {
×
93
    case ValueType::Illegal:
×
94
    case ValueType::None:
95
    case ValueType::Null:
96
      // Null equals Null
97
    case ValueType::MinKey:
98
    case ValueType::MaxKey: {
99
      return true;
×
100
    }
101
    case ValueType::Bool: {
×
102
      return (lhs.getBoolean() == rhs.getBoolean());
×
103
    }
104
    case ValueType::Double:
×
105
    case ValueType::Int:
106
    case ValueType::UInt:
107
    case ValueType::SmallInt: {
108
      return equalsNumbers(lhs, rhs);
×
109
    }
110
    case ValueType::String: {
×
111
      return equalsStrings(lhs, rhs);
×
112
    }
113
    case ValueType::Array: {
×
114
      ArrayIterator lhsValue(lhs);
×
115
      ArrayIterator rhsValue(rhs);
×
116

117
      ValueLength const n = lhsValue.size();
×
118
      if (n != rhsValue.size()) {
×
119
        // unequal array lengths
120
        return false;
×
121
      }
122
      for (ValueLength i = 0; i < n; ++i) {
×
123
        // recurse
124
        if (!equals(lhsValue.value(), rhsValue.value())) {
×
125
          return false;
×
126
        }
127
        lhsValue.next();
×
128
        rhsValue.next();
×
129
      }
130
      return true;
×
131
    }
132
    case ValueType::Object: {
×
133
      std::set<std::string> keys;
×
134
      // get all keys and bring them in order
135
      Collection::unorderedKeys(lhs, keys);
×
136
      Collection::unorderedKeys(rhs, keys);
×
137
      for (auto const& key : keys) {
×
138
        // recurse
139
        if (!equals(lhs.get(key), rhs.get(key))) {
×
140
          return false;
×
141
        }
142
      }
143
      return true;
×
144
    }
145
    case ValueType::Custom: {
×
146
      throw Exception(Exception::NotImplemented,
×
147
                      "equals comparison for Custom type is not implemented");
×
148
    }
149
    default: {
×
150
      throw Exception(Exception::InternalError,
×
151
                      "invalid value type for equals comparison");
×
152
    }
153
  }
154
}
155

156
size_t NormalizedCompare::Hash::operator()(
×
157
    arangodb::velocypack::Slice const& slice) const {
158
  return static_cast<size_t>(slice.normalizedHash());
×
159
}
160

161
bool NormalizedCompare::Equal::operator()(
×
162
    arangodb::velocypack::Slice const& lhs,
163
    arangodb::velocypack::Slice const& rhs) const {
164
  return NormalizedCompare::equals(lhs, rhs);
×
165
}
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