[QUEUED scylla next] types: convert abstract_type::compare and related to std::strong_ordering

0 views
Skip to first unread message

Commit Bot

unread,
Jul 29, 2021, 3:44:20 PMJul 29
to scylla...@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: next

types: convert abstract_type::compare and related to std::strong_ordering

Change comparators around types to std::strong_ordering.

Ref #1449.

---
diff --git a/cdc/log.cc b/cdc/log.cc
--- a/cdc/log.cc
+++ b/cdc/log.cc
@@ -712,17 +712,17 @@ class maybe_back_insert_iterator : public std::back_insert_iterator<Container> {
}
return false;
}
- int32_t compare(const T&, const value_type& v);
+ std::strong_ordering compare(const T&, const value_type& v);
};

template<>
-int32_t maybe_back_insert_iterator<std::vector<std::pair<managed_bytes_view, managed_bytes_view>>, managed_bytes_view>::compare(
+std::strong_ordering maybe_back_insert_iterator<std::vector<std::pair<managed_bytes_view, managed_bytes_view>>, managed_bytes_view>::compare(
const managed_bytes_view& t, const value_type& v) {
return _type.compare(t, v.first);
}

template<>
-int32_t maybe_back_insert_iterator<std::vector<managed_bytes_view>, managed_bytes_view>::compare(const managed_bytes_view& t, const value_type& v) {
+std::strong_ordering maybe_back_insert_iterator<std::vector<managed_bytes_view>, managed_bytes_view>::compare(const managed_bytes_view& t, const value_type& v) {
return _type.compare(t, v);
}

diff --git a/clustering_bounds_comparator.hh b/clustering_bounds_comparator.hh
--- a/clustering_bounds_comparator.hh
+++ b/clustering_bounds_comparator.hh
@@ -64,29 +64,29 @@ public:
std::reference_wrapper<const schema> _s;
tri_compare(const schema& s) : _s(s)
{ }
- int operator()(const clustering_key_prefix& p1, int32_t w1, const clustering_key_prefix& p2, int32_t w2) const {
+ std::strong_ordering operator()(const clustering_key_prefix& p1, int32_t w1, const clustering_key_prefix& p2, int32_t w2) const {
auto type = _s.get().clustering_key_prefix_type();
auto res = prefix_equality_tri_compare(type->types().begin(),
type->begin(p1.representation()), type->end(p1.representation()),
type->begin(p2.representation()), type->end(p2.representation()),
- ::tri_compare);
- if (res) {
+ ::tri_compare) <=> 0;
+ if (res != 0) {
return res;
}
auto d1 = p1.size(_s);
auto d2 = p2.size(_s);
if (d1 == d2) {
- return w1 - w2;
+ return w1 <=> w2;
}
- return d1 < d2 ? w1 - (w1 <= 0) : -(w2 - (w2 <= 0));
+ return (d1 < d2 ? w1 - (w1 <= 0) : -(w2 - (w2 <= 0))) <=> 0;
}
- int operator()(const bound_view b, const clustering_key_prefix& p) const {
+ std::strong_ordering operator()(const bound_view b, const clustering_key_prefix& p) const {
return operator()(b._prefix, weight(b._kind), p, 0);
}
- int operator()(const clustering_key_prefix& p, const bound_view b) const {
+ std::strong_ordering operator()(const clustering_key_prefix& p, const bound_view b) const {
return operator()(p, 0, b._prefix, weight(b._kind));
}
- int operator()(const bound_view b1, const bound_view b2) const {
+ std::strong_ordering operator()(const bound_view b1, const bound_view b2) const {
return operator()(b1._prefix, weight(b1._kind), b2._prefix, weight(b2._kind));
}
};
diff --git a/compound.hh b/compound.hh
--- a/compound.hh
+++ b/compound.hh
@@ -248,24 +248,24 @@ public:
}
return h;
}
- int compare(managed_bytes_view b1, managed_bytes_view b2) const {
+ std::strong_ordering compare(managed_bytes_view b1, managed_bytes_view b2) const {
return with_linearized(b1, [&] (bytes_view bv1) {
return with_linearized(b2, [&] (bytes_view bv2) {
- return compare(bv1, bv2);
+ return compare(bv1, bv2) <=> 0;
});
});
}
- int compare(bytes_view b1, bytes_view b2) const {
+ std::strong_ordering compare(bytes_view b1, bytes_view b2) const {
if (_byte_order_comparable) {
if (_is_reversed) {
- return compare_unsigned(b2, b1);
+ return compare_unsigned(b2, b1) <=> 0;
} else {
- return compare_unsigned(b1, b2);
+ return compare_unsigned(b1, b2) <=> 0;
}
}
return lexicographical_tri_compare(_types.begin(), _types.end(),
begin(b1), end(b1), begin(b2), end(b2), [] (auto&& type, auto&& v1, auto&& v2) {
- return type->compare(v1, v2);
+ return type->compare(v1, v2) <=> 0;
});
}
// Retruns true iff given prefix has no missing components
diff --git a/cql3/column_condition.cc b/cql3/column_condition.cc
--- a/cql3/column_condition.cc
+++ b/cql3/column_condition.cc
@@ -68,7 +68,7 @@ void validate_operation_on_durations(const abstract_type& type, cql3::expr::oper
int is_satisfied_by(cql3::expr::oper_t op, const abstract_type& cell_type,
const abstract_type& param_type, const data_value& cell_value, const bytes& param) {

- int rc;
+ std::strong_ordering rc = std::strong_ordering::equal;
// For multi-cell sets and lists, cell value is represented as a map,
// thanks to collections_as_maps flag in partition_slice. param, however,
// is represented as a set or list type.
@@ -79,7 +79,7 @@ int is_satisfied_by(cql3::expr::oper_t op, const abstract_type& cell_type,
const map_type_impl& map_type = static_cast<const map_type_impl&>(cell_type);
assert(list_type.is_multi_cell());
// Inverse comparison result since the order of arguments is inverse.
- rc = -list_type.compare_with_map(map_type, param, map_type.decompose(cell_value));
+ rc = 0 <=> list_type.compare_with_map(map_type, param, map_type.decompose(cell_value));
} else {
rc = cell_type.compare(cell_type.decompose(cell_value), param);
}
diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc
--- a/cql3/statements/select_statement.cc
+++ b/cql3/statements/select_statement.cc
@@ -1591,7 +1591,7 @@ select_statement::get_ordering_comparator(const schema& schema,
return bool(c2);
}
if (c1) {
- int result = type->compare(*c1, *c2);
+ auto result = type->compare(*c1, *c2);
if (result != 0) {
return result < 0;
}
diff --git a/position_in_partition.hh b/position_in_partition.hh
--- a/position_in_partition.hh
+++ b/position_in_partition.hh
@@ -380,48 +380,48 @@ public:

composite_tri_compare(const schema& s) : _s(s) {}

- int operator()(position_in_partition_view a, position_in_partition_view b) const {
+ std::strong_ordering operator()(position_in_partition_view a, position_in_partition_view b) const {
if (a._type != b._type) {
- return rank(a._type) - rank(b._type);
+ return rank(a._type) <=> rank(b._type);
}
if (!a._ck) {
- return 0;
+ return std::strong_ordering::equal;
}
auto&& types = _s.clustering_key_type()->types();
auto cmp = [&] (const data_type& t, managed_bytes_view c1, managed_bytes_view c2) { return t->compare(c1, c2); };
return lexicographical_tri_compare(types.begin(), types.end(),
a._ck->begin(_s), a._ck->end(_s),
b._ck->begin(_s), b._ck->end(_s),
- cmp, a.relation(), b.relation());
+ cmp, a.relation(), b.relation()) <=> 0;
}

- int operator()(position_in_partition_view a, composite_view b) const {
+ std::strong_ordering operator()(position_in_partition_view a, composite_view b) const {
if (b.empty()) {
- return 1; // a cannot be empty.
+ return std::strong_ordering::greater; // a cannot be empty.
}
partition_region b_type = b.is_static() ? partition_region::static_row : partition_region::clustered;
if (a._type != b_type) {
- return rank(a._type) - rank(b_type);
+ return rank(a._type) <=> rank(b_type);
}
if (!a._ck) {
- return 0;
+ return std::strong_ordering::equal;
}
auto&& types = _s.clustering_key_type()->types();
auto b_values = b.values();
auto cmp = [&] (const data_type& t, managed_bytes_view c1, managed_bytes_view c2) { return t->compare(c1, c2); };
return lexicographical_tri_compare(types.begin(), types.end(),
a._ck->begin(_s), a._ck->end(_s),
b_values.begin(), b_values.end(),
- cmp, a.relation(), relation_for_lower_bound(b));
+ cmp, a.relation(), relation_for_lower_bound(b)) <=> 0;
}

- int operator()(composite_view a, position_in_partition_view b) const {
- return -(*this)(b, a);
+ std::strong_ordering operator()(composite_view a, position_in_partition_view b) const {
+ return 0 <=> (*this)(b, a);
}

- int operator()(composite_view a, composite_view b) const {
+ std::strong_ordering operator()(composite_view a, composite_view b) const {
if (a.is_static() != b.is_static()) {
- return a.is_static() ? -1 : 1;
+ return a.is_static() ? std::strong_ordering::less : std::strong_ordering::greater;
}
auto&& types = _s.clustering_key_type()->types();
auto a_values = a.values();
@@ -432,7 +432,7 @@ public:
b_values.begin(), b_values.end(),
cmp,
relation_for_lower_bound(a),
- relation_for_lower_bound(b));
+ relation_for_lower_bound(b)) <=> 0;
}
};

diff --git a/test/boost/types_test.cc b/test/boost/types_test.cc
--- a/test/boost/types_test.cc
+++ b/test/boost/types_test.cc
@@ -734,7 +734,7 @@ BOOST_AUTO_TEST_CASE(test_create_reversed_type) {
auto val_gt = bytes_type->decompose(data_value(bytes("b")));
auto straight_comp = bytes_type->compare(bytes_view(val_lt), bytes_view(val_gt));
auto reverse_comp = ri->compare(bytes_view(val_lt), bytes_view(val_gt));
- BOOST_REQUIRE(straight_comp == -reverse_comp);
+ BOOST_REQUIRE(straight_comp == (0 <=> reverse_comp));
}

BOOST_AUTO_TEST_CASE(test_reversed_type_to_string) {
@@ -766,7 +766,7 @@ BOOST_AUTO_TEST_CASE(test_create_reverse_collection_type) {

auto straight_comp = my_set_type->compare(bytes_view(bv1), bytes_view(bv2));
auto reverse_comp = ri->compare(bytes_view(bv2), bytes_view(bv2));
- BOOST_REQUIRE(straight_comp == -reverse_comp);
+ BOOST_REQUIRE(straight_comp == (0 <=> reverse_comp));
}

BOOST_AUTO_TEST_CASE(test_parse_reversed_type) {
@@ -782,7 +782,7 @@ BOOST_AUTO_TEST_CASE(test_parse_reversed_type) {
auto val_gt = int32_type->decompose(2);
auto straight_comp = int32_type->compare(bytes_view(val_lt), bytes_view(val_gt));
auto reverse_comp = ri->compare(bytes_view(val_lt), bytes_view(val_gt));
- BOOST_REQUIRE(straight_comp == -reverse_comp);
+ BOOST_REQUIRE(straight_comp == (0 <=> reverse_comp));
}

BOOST_AUTO_TEST_CASE(test_reversed_type_value_compatibility) {
diff --git a/tools/scylla-types.cc b/tools/scylla-types.cc
--- a/tools/scylla-types.cc
+++ b/tools/scylla-types.cc
@@ -74,13 +74,13 @@ void compare_handler(type_variant type, std::vector<bytes> values) {
struct {
bytes_view lhs, rhs;

- int operator()(const data_type& type) {
+ std::strong_ordering operator()(const data_type& type) {
return type->compare(lhs, rhs);
}
- int operator()(const compound_type<allow_prefixes::yes>& type) {
+ std::strong_ordering operator()(const compound_type<allow_prefixes::yes>& type) {
return type.compare(lhs, rhs);
}
- int operator()(const compound_type<allow_prefixes::no>& type) {
+ std::strong_ordering operator()(const compound_type<allow_prefixes::no>& type) {
return type.compare(lhs, rhs);
}
} compare_visitor{values[0], values[1]};
diff --git a/types.cc b/types.cc
--- a/types.cc
+++ b/types.cc
@@ -512,14 +512,14 @@ listlike_collection_type_impl::listlike_collection_type_impl(
kind k, sstring name, data_type elements, bool is_multi_cell)
: collection_type_impl(k, name, is_multi_cell), _elements(elements) {}

-int listlike_collection_type_impl::compare_with_map(const map_type_impl& map_type, bytes_view list, bytes_view map) const
+std::strong_ordering listlike_collection_type_impl::compare_with_map(const map_type_impl& map_type, bytes_view list, bytes_view map) const
{
assert((is_set() && map_type.get_keys_type() == _elements) || (!is_set() && map_type.get_values_type() == _elements));

if (list.empty()) {
- return map.empty() ? 0 : -1;
+ return map.empty() ? std::strong_ordering::equal : std::strong_ordering::less;
} else if (map.empty()) {
- return 1;
+ return std::strong_ordering::greater;
}

const abstract_type& element_type = *_elements;
@@ -545,7 +545,7 @@ int listlike_collection_type_impl::compare_with_map(const map_type_impl& map_typ
return cmp;
}
}
- return list_size == map_size ? 0 : (list_size < map_size ? -1 : 1);
+ return list_size <=> map_size;
}

bytes listlike_collection_type_impl::serialize_map(const map_type_impl& map_type, const data_value& value) const
@@ -1078,12 +1078,12 @@ map_type_impl::is_value_compatible_with_frozen(const collection_type_impl& previ
&& _values->is_value_compatible_with(*p->_values);
}

-int32_t
+std::strong_ordering
map_type_impl::compare_maps(data_type keys, data_type values, managed_bytes_view o1, managed_bytes_view o2) {
if (o1.empty()) {
- return o2.empty() ? 0 : -1;
+ return o2.empty() ? std::strong_ordering::equal : std::strong_ordering::less;
} else if (o2.empty()) {
- return 1;
+ return std::strong_ordering::greater;
}
auto sf = cql_serialization_format::internal();
int size1 = read_collection_size(o1, sf);
@@ -1103,7 +1103,7 @@ map_type_impl::compare_maps(data_type keys, data_type values, managed_bytes_view
return cmp;
}
}
- return size1 == size2 ? 0 : (size1 < size2 ? -1 : 1);
+ return size1 <=> size2;
}

static size_t map_serialized_size(const map_type_impl::native_type* m) {
@@ -2141,7 +2141,7 @@ template data_value abstract_type::deserialize_impl<>(single_fragmented_view) co
template data_value abstract_type::deserialize_impl<>(ser::buffer_view<bytes_ostream::fragment_iterator>) const;
template data_value abstract_type::deserialize_impl<>(managed_bytes_view) const;

-int32_t compare_aux(const tuple_type_impl& t, const managed_bytes_view& v1, const managed_bytes_view& v2) {
+std::strong_ordering compare_aux(const tuple_type_impl& t, const managed_bytes_view& v1, const managed_bytes_view& v2) {
// This is a slight modification of lexicographical_tri_compare:
// when the only difference between the tuples is that one of them has additional trailing nulls,
// we consider them equal. For example, in the following CQL scenario:
@@ -2163,7 +2163,7 @@ int32_t compare_aux(const tuple_type_impl& t, const managed_bytes_view& v1, cons
auto last2 = tuple_deserializing_iterator::finish(v2);

while (types_first != types_last && first1 != last1 && first2 != last2) {
- if (auto c = tri_compare_opt(*types_first, *first1, *first2)) {
+ if (auto c = tri_compare_opt(*types_first, *first1, *first2); c != 0) {
return c;
}

@@ -2174,7 +2174,7 @@ int32_t compare_aux(const tuple_type_impl& t, const managed_bytes_view& v1, cons

while (types_first != types_last && first1 != last1) {
if (*first1) {
- return 1;
+ return std::strong_ordering::greater;
}

++first1;
@@ -2183,14 +2183,14 @@ int32_t compare_aux(const tuple_type_impl& t, const managed_bytes_view& v1, cons

while (types_first != types_last && first2 != last2) {
if (*first2) {
- return -1;
+ return std::strong_ordering::less;
}

++first2;
++types_first;
}

- return 0;
+ return std::strong_ordering::equal;
}

namespace {
@@ -2200,128 +2200,129 @@ struct compare_visitor {
managed_bytes_view v2;

template <std::invocable<> Func>
- requires std::same_as<int32_t, std::invoke_result_t<Func>>
- int32_t with_empty_checks(Func func) {
+ requires std::same_as<std::strong_ordering, std::invoke_result_t<Func>>
+ std::strong_ordering with_empty_checks(Func func) {
if (v1.empty()) {
- return v2.empty() ? 0 : -1;
+ return v2.empty() ? std::strong_ordering::equal : std::strong_ordering::less;
}
if (v2.empty()) {
- return 1;
+ return std::strong_ordering::greater;
}
return func();
}

- template <typename T> int32_t operator()(const simple_type_impl<T>&) {
+ template <typename T> std::strong_ordering operator()(const simple_type_impl<T>&) {
return with_empty_checks([&] {
T a = simple_type_traits<T>::read_nonempty(v1);
T b = simple_type_traits<T>::read_nonempty(v2);
- return a == b ? 0 : a < b ? -1 : 1;
+ return a <=> b;
});
}
- int32_t operator()(const string_type_impl&) { return compare_unsigned(v1, v2); }
- int32_t operator()(const bytes_type_impl&) { return compare_unsigned(v1, v2); }
- int32_t operator()(const duration_type_impl&) { return compare_unsigned(v1, v2); }
- int32_t operator()(const inet_addr_type_impl&) { return compare_unsigned(v1, v2); }
- int32_t operator()(const date_type_impl&) {
+ std::strong_ordering operator()(const string_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
+ std::strong_ordering operator()(const bytes_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
+ std::strong_ordering operator()(const duration_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
+ std::strong_ordering operator()(const inet_addr_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
+ std::strong_ordering operator()(const date_type_impl&) {
// This is not the same behaviour as timestamp_type_impl
- return compare_unsigned(v1, v2);
+ return compare_unsigned(v1, v2) <=> 0;
}
- int32_t operator()(const timeuuid_type_impl&) {
+ std::strong_ordering operator()(const timeuuid_type_impl&) {
return with_empty_checks([&] {
return with_linearized(v1, [&] (bytes_view v1) {
return with_linearized(v2, [&] (bytes_view v2) {
- return utils::timeuuid_tri_compare(v1, v2);
+ return utils::timeuuid_tri_compare(v1, v2) <=> 0;
});
});
});
}
- int32_t operator()(const listlike_collection_type_impl& l) {
+ std::strong_ordering operator()(const listlike_collection_type_impl& l) {
using llpdi = listlike_partial_deserializing_iterator;
auto sf = cql_serialization_format::internal();
return lexicographical_tri_compare(llpdi::begin(v1, sf), llpdi::end(v1, sf), llpdi::begin(v2, sf),
llpdi::end(v2, sf),
[&] (const managed_bytes_view& o1, const managed_bytes_view& o2) { return l.get_elements_type()->compare(o1, o2); });
}
- int32_t operator()(const map_type_impl& m) {
+ std::strong_ordering operator()(const map_type_impl& m) {
return map_type_impl::compare_maps(m.get_keys_type(), m.get_values_type(), v1, v2);
}
- int32_t operator()(const uuid_type_impl&) {
+ std::strong_ordering operator()(const uuid_type_impl&) {
if (v1.size() < 16) {
- return v2.size() < 16 ? 0 : -1;
+ return v2.size() < 16 ? std::strong_ordering::equal : std::strong_ordering::less;
}
if (v2.size() < 16) {

- return 1;
+ return std::strong_ordering::greater;
}
auto c1 = (v1[6] >> 4) & 0x0f;
auto c2 = (v2[6] >> 4) & 0x0f;

if (c1 != c2) {
- return c1 - c2;
+ return c1 <=> c2;
}

if (c1 == 1) {
return with_linearized(v1, [&] (bytes_view v1) {
return with_linearized(v2, [&] (bytes_view v2) {
- return utils::uuid_tri_compare_timeuuid(v1, v2);
+ return utils::uuid_tri_compare_timeuuid(v1, v2) <=> 0;
});
});
}
- return compare_unsigned(v1, v2);
+ return compare_unsigned(v1, v2) <=> 0;
}
- int32_t operator()(const empty_type_impl&) { return 0; }
- int32_t operator()(const tuple_type_impl& t) { return compare_aux(t, v1, v2); }
- int32_t operator()(const counter_type_impl&) {
+ std::strong_ordering operator()(const empty_type_impl&) { return std::strong_ordering::equal; }
+ std::strong_ordering operator()(const tuple_type_impl& t) { return compare_aux(t, v1, v2); }
+ std::strong_ordering operator()(const counter_type_impl&) {
// untouched (empty) counter evaluates as 0
const auto a = v1.empty() ? 0 : simple_type_traits<int64_t>::read_nonempty(v1);
const auto b = v2.empty() ? 0 : simple_type_traits<int64_t>::read_nonempty(v2);
- return a == b ? 0 : a < b ? -1 : 1;
+ return a <=> b;
}
- int32_t operator()(const decimal_type_impl& d) {
+ std::strong_ordering operator()(const decimal_type_impl& d) {
return with_empty_checks([&] {
auto a = deserialize_value(d, v1);
auto b = deserialize_value(d, v2);
- return a.compare(b);
+ return a.compare(b) <=> 0;
});
}
- int32_t operator()(const varint_type_impl& v) {
+ std::strong_ordering operator()(const varint_type_impl& v) {
return with_empty_checks([&] {
auto a = deserialize_value(v, v1);
auto b = deserialize_value(v, v2);
- return a == b ? 0 : a < b ? -1 : 1;
+ return a == b ? std::strong_ordering::equal : a < b ? std::strong_ordering::less : std::strong_ordering::greater;
});
}
- template <typename T> int32_t operator()(const floating_type_impl<T>&) {
+ template <typename T> std::strong_ordering operator()(const floating_type_impl<T>&) {
return with_empty_checks([&] {
T a = simple_type_traits<T>::read_nonempty(v1);
T b = simple_type_traits<T>::read_nonempty(v2);

// in java world NaN == NaN and NaN is greater than anything else
if (std::isnan(a) && std::isnan(b)) {
- return 0;
+ return std::strong_ordering::equal;
} else if (std::isnan(a)) {
- return 1;
+ return std::strong_ordering::greater;
} else if (std::isnan(b)) {
- return -1;
+ return std::strong_ordering::less;
}
// also -0 < 0
if (std::signbit(a) && !std::signbit(b)) {
- return -1;
+ return std::strong_ordering::less;
} else if (!std::signbit(a) && std::signbit(b)) {
- return 1;
+ return std::strong_ordering::greater;
}
- return a == b ? 0 : a < b ? -1 : 1;
+ // note: float <=> returns std::partial_ordering
+ return a == b ? std::strong_ordering::equal : a < b ? std::strong_ordering::less : std::strong_ordering::greater;
});
}
- int32_t operator()(const reversed_type_impl& r) { return r.underlying_type()->compare(v2, v1); }
+ std::strong_ordering operator()(const reversed_type_impl& r) { return r.underlying_type()->compare(v2, v1); }
};
}

-int32_t abstract_type::compare(bytes_view v1, bytes_view v2) const {
+std::strong_ordering abstract_type::compare(bytes_view v1, bytes_view v2) const {
return compare(managed_bytes_view(v1), managed_bytes_view(v2));
}

-int32_t abstract_type::compare(managed_bytes_view v1, managed_bytes_view v2) const {
+std::strong_ordering abstract_type::compare(managed_bytes_view v1, managed_bytes_view v2) const {
try {
return visit(*this, compare_visitor{v1, v2});
} catch (const marshal_exception&) {
diff --git a/types.hh b/types.hh
--- a/types.hh
+++ b/types.hh
@@ -574,8 +574,8 @@ public:
size_t hash(managed_bytes_view v) const;
bool equal(bytes_view v1, bytes_view v2) const;
bool equal(managed_bytes_view v1, managed_bytes_view v2) const;
- int32_t compare(bytes_view v1, bytes_view v2) const;
- int32_t compare(managed_bytes_view v1, managed_bytes_view v2) const;
+ std::strong_ordering compare(bytes_view v1, bytes_view v2) const;
+ std::strong_ordering compare(managed_bytes_view v1, managed_bytes_view v2) const;

private:
// Explicitly instantiated in .cc
@@ -803,15 +803,15 @@ bool less_compare(data_type t, bytes_view e1, bytes_view e2) {
}

static inline
-int tri_compare(data_type t, managed_bytes_view e1, managed_bytes_view e2) {
+std::strong_ordering tri_compare(data_type t, managed_bytes_view e1, managed_bytes_view e2) {
return t->compare(e1, e2);
}

inline
-int
+std::strong_ordering
tri_compare_opt(data_type t, managed_bytes_view_opt v1, managed_bytes_view_opt v2) {
if (!v1 || !v2) {
- return int(bool(v1)) - int(bool(v2));
+ return int(bool(v1)) - int(bool(v2)) <=> 0;
} else {
return tri_compare(std::move(t), *v1, *v2);
}
diff --git a/types/collection.hh b/types/collection.hh
--- a/types/collection.hh
+++ b/types/collection.hh
@@ -105,7 +105,7 @@ public:
//
// This function is used to compare receiver with a literal or parameter marker during condition
// evaluation.
- int32_t compare_with_map(const map_type_impl& map_type, bytes_view list, bytes_view map) const;
+ std::strong_ordering compare_with_map(const map_type_impl& map_type, bytes_view list, bytes_view map) const;
// A list or set value can be represented as a vector<pair<timeuuid, data_value>> or
// vector<pair<data_value, empty>> respectively. Serialize this representation
// as a vector of values, not as a vector of pairs.
diff --git a/types/map.hh b/types/map.hh
--- a/types/map.hh
+++ b/types/map.hh
@@ -52,7 +52,7 @@ public:
virtual data_type freeze() const override;
virtual bool is_compatible_with_frozen(const collection_type_impl& previous) const override;
virtual bool is_value_compatible_with_frozen(const collection_type_impl& previous) const override;
- static int32_t compare_maps(data_type keys_comparator, data_type values_comparator,
+ static std::strong_ordering compare_maps(data_type keys_comparator, data_type values_comparator,
managed_bytes_view o1, managed_bytes_view o2);
using abstract_type::deserialize;
using collection_type_impl::deserialize;

Commit Bot

unread,
Jul 29, 2021, 9:40:10 PMJul 29
to scylla...@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master
Reply all
Reply to author
Forward
0 new messages