mirror of https://github.com/ByConity/ByConity
Adapt UInt128 operator
This commit is contained in:
parent
aeeb81fadf
commit
b90734920e
|
@ -26,23 +26,25 @@ struct UInt128
|
|||
|
||||
UInt128() = default;
|
||||
explicit UInt128(const UInt64 rhs) : low(0), high(rhs) { }
|
||||
explicit UInt128(const UInt64 low, const UInt64 high) : low(low), high(high) { }
|
||||
|
||||
bool operator== (const UInt128 rhs) const { return std::forward_as_tuple(low, high) == std::forward_as_tuple(rhs.low, rhs.high); }
|
||||
bool operator!= (const UInt128 rhs) const { return std::forward_as_tuple(low, high) != std::forward_as_tuple(rhs.low, rhs.high); }
|
||||
bool operator>= (const UInt128 rhs) const { return (low == rhs.low) ? high >= rhs.high : low > rhs.low; }
|
||||
bool operator> (const UInt128 rhs) const { return (low == rhs.low) ? high > rhs.high : low > rhs.low; }
|
||||
bool operator<= (const UInt128 rhs) const { return (low == rhs.low) ? high <= rhs.high : low < rhs.low; }
|
||||
bool operator< (const UInt128 rhs) const { return (low == rhs.low) ? high < rhs.high : low < rhs.low; }
|
||||
bool inline operator== (const UInt128 rhs) const { return std::tie(low, high) == std::tie(rhs.low, rhs.high); }
|
||||
bool inline operator!= (const UInt128 rhs) const { return !(*this == rhs); }
|
||||
|
||||
bool inline operator< (const UInt128 rhs) const { return std::tie(low, high) < std::tie(rhs.low, rhs.high); }
|
||||
bool inline operator<= (const UInt128 rhs) const { return !(rhs < *this); }
|
||||
bool inline operator> (const UInt128 rhs) const { return rhs < *this; }
|
||||
bool inline operator>= (const UInt128 rhs) const { return !(*this < rhs); }
|
||||
|
||||
/** Type stored in the database will contain no more than 64 bits at the moment, don't need
|
||||
* to check the `second` element
|
||||
* to check the `high` element
|
||||
*/
|
||||
template<typename T> bool operator== (const T rhs) const { return low == 0 && static_cast<T>(high) == rhs; }
|
||||
template<typename T> bool operator!= (const T rhs) const { return low != 0 || static_cast<T>(high) != rhs; }
|
||||
template<typename T> bool operator>= (const T rhs) const { return low != 0 && static_cast<T>(high) >= rhs; }
|
||||
template<typename T> bool operator> (const T rhs) const { return low != 0 && static_cast<T>(high) > rhs; }
|
||||
template<typename T> bool operator<= (const T rhs) const { return low == 0 && static_cast<T>(high) <= rhs; }
|
||||
template<typename T> bool operator< (const T rhs) const { return low == 0 && static_cast<T>(high) > rhs; }
|
||||
template<typename T> bool inline operator== (const T rhs) const { return *this == UInt128(0, rhs); }
|
||||
template<typename T> bool inline operator!= (const T rhs) const { return *this != UInt128(0, rhs); }
|
||||
template<typename T> bool inline operator>= (const T rhs) const { return *this >= UInt128(0, rhs); }
|
||||
template<typename T> bool inline operator> (const T rhs) const { return *this > UInt128(0, rhs); }
|
||||
template<typename T> bool inline operator<= (const T rhs) const { return *this <= UInt128(0, rhs); }
|
||||
template<typename T> bool inline operator< (const T rhs) const { return *this < UInt128(0, rhs); }
|
||||
|
||||
template<typename T> explicit operator T() const { return static_cast<T>(high); }
|
||||
|
||||
|
@ -53,12 +55,12 @@ struct UInt128
|
|||
UInt128 & operator= (const UInt64 rhs) { low = 0; high = rhs; return *this; }
|
||||
};
|
||||
|
||||
template<typename T> bool operator== (T a, const UInt128 b) { return b == a; }
|
||||
template<typename T> bool operator!= (T a, const UInt128 b) { return b != a; }
|
||||
template<typename T> bool operator>= (T a, const UInt128 b) { return b.low == 0 && a >= static_cast<T>(b.high); }
|
||||
template<typename T> bool operator> (T a, const UInt128 b) { return b.low == 0 && a > static_cast<T>(b.high); }
|
||||
template<typename T> bool operator<= (T a, const UInt128 b) { return b.low != 0 || a <= static_cast<T>(b.high); }
|
||||
template<typename T> bool operator< (T a, const UInt128 b) { return b.low != 0 || a < static_cast<T>(b.high); }
|
||||
template<typename T> bool inline operator== (T a, const UInt128 b) { return b == a; }
|
||||
template<typename T> bool inline operator!= (T a, const UInt128 b) { return b != a; }
|
||||
template<typename T> bool inline operator>= (T a, const UInt128 b) { return b.low == 0 && a >= static_cast<T>(b.high); }
|
||||
template<typename T> bool inline operator> (T a, const UInt128 b) { return b.low == 0 && a > static_cast<T>(b.high); }
|
||||
template<typename T> bool inline operator<= (T a, const UInt128 b) { return b.low != 0 || a <= static_cast<T>(b.high); }
|
||||
template<typename T> bool inline operator< (T a, const UInt128 b) { return b.low != 0 || a < static_cast<T>(b.high); }
|
||||
|
||||
struct UInt128Hash
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
DROP TABLE IF EXISTS test.insert;
|
||||
CREATE TABLE test.insert (i UInt64, s String, u UUID, d Date, t DateTime, a Array(UInt32)) ENGINE = Memory;
|
||||
|
||||
INSERT INTO test.insert VALUES (1, 'Hello', 'ab41bdd6-5cd4-11e7-907b-a6006ad3dba0', '2016-01-01', '2016-01-02 03:04:05', [1, 2, 3]), (1 + 1, concat('Hello', ', world'), toUuid(0), toDate('2016-01-01') + 1, toStartOfMinute(toDateTime('2016-01-02 03:04:05')), [[0,1],[2]][1]), (round(pi()), concat('hello', ', world!'), toUuid(toString('ab41bdd6-5cd4-11e7-907b-a6006ad3dba0')), toDate(toDateTime('2016-01-03 03:04:05')), toStartOfHour(toDateTime('2016-01-02 03:04:05')), []), (4, 'World', 'ab41bdd6-5cd4-11e7-907b-a6006ad3dba0', '2016-01-04', '2016-12-11 10:09:08', [3,2,1]);
|
||||
INSERT INTO test.insert VALUES (1, 'Hello', 'ab41bdd6-5cd4-11e7-907b-a6006ad3dba0', '2016-01-01', '2016-01-02 03:04:05', [1, 2, 3]), (1 + 1, concat('Hello', ', world'), toUUID(0), toDate('2016-01-01') + 1, toStartOfMinute(toDateTime('2016-01-02 03:04:05')), [[0,1],[2]][1]), (round(pi()), concat('hello', ', world!'), toUUID(toString('ab41bdd6-5cd4-11e7-907b-a6006ad3dba0')), toDate(toDateTime('2016-01-03 03:04:05')), toStartOfHour(toDateTime('2016-01-02 03:04:05')), []), (4, 'World', 'ab41bdd6-5cd4-11e7-907b-a6006ad3dba0', '2016-01-04', '2016-12-11 10:09:08', [3,2,1]);
|
||||
|
||||
SELECT * FROM test.insert ORDER BY i;
|
||||
DROP TABLE test.insert;
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') = '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' = toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') = '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' = toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') = '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' = toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') = '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' = toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') != '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' != toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') != '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' != toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') != '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' != toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') != '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' != toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
|
||||
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') < '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' < toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1') < '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba1' < toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') < '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' < toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') < '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' < toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1') < '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba1' < toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') < '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' < toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
|
||||
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') > '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' > toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba2') > '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba2' > toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1') > '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba1' > toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') > '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' > toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba2') > '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba2' > toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1') > '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba1' > toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
|
||||
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') <= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' <= toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') <= '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' <= toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba2') <= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba2' <= toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') <= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' <= toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') <= '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' <= toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba2') <= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba2' <= toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') >= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' >= toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0') >= '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' >= toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba2') >= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba2' >= toUuid('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') >= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' >= toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') >= '61f0c404-5cb3-11e7-907b-a6006ad3dba0';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba0' >= toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0');
|
||||
SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba2') >= '61f0c404-5cb3-11e7-907b-a6006ad3dba1';
|
||||
SELECT '61f0c404-5cb3-11e7-907b-a6006ad3dba2' >= toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba1');
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue