Rename field in UInt128

This commit is contained in:
Guillaume Tassery 2017-07-04 18:10:36 +02:00
parent cba9815981
commit aeeb81fadf
10 changed files with 44 additions and 45 deletions

View File

@ -314,7 +314,7 @@ struct OneAdder<T, Data, typename std::enable_if<
UInt128 key;
SipHash hash;
hash.update(value.data, value.size);
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
data.set.insert(key);
}

View File

@ -100,7 +100,7 @@ struct UniqVariadicHash<true, false>
}
UInt128 key;
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
return key;
}
};
@ -124,7 +124,7 @@ struct UniqVariadicHash<true, true>
}
UInt128 key;
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
return key;
}
};

View File

@ -15,57 +15,56 @@ namespace DB
/// For aggregation by SipHash, UUID type or concatenation of several fields.
struct UInt128
{
/// Suppress gcc7 warnings: 'prev_key.DB::UInt128::first' may be used uninitialized in this function
/// Suppress gcc7 warnings: 'prev_key.DB::UInt128::low' may be used uninitialized in this function
#if !__clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
UInt64 first;
UInt64 second;
UInt64 low;
UInt64 high;
UInt128() = default;
explicit UInt128(const UInt64 rhs) : first(0), second(rhs) { }
explicit UInt128(const UInt64 rhs) : low(0), high(rhs) { }
bool operator== (const UInt128 & rhs) const { return second == rhs.second && first == rhs.first; }
bool operator!= (const UInt128 & rhs) const { return second != rhs.second || first != rhs.first; }
bool operator>= (const UInt128 & rhs) const { return (first == rhs.first) ? second >= rhs.second : first > rhs.first; }
bool operator> (const UInt128 & rhs) const { return (first == rhs.first) ? second > rhs.second : first > rhs.first; }
bool operator<= (const UInt128 & rhs) const { return (first == rhs.first) ? second <= rhs.second : first < rhs.first; }
bool operator< (const UInt128 & rhs) const { return (first == rhs.first) ? second < rhs.second : first < rhs.first; }
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; }
/** Type stored in the database will contains no more than 64 bits at the moment, don't need
/** Type stored in the database will contain no more than 64 bits at the moment, don't need
* to check the `second` element
*/
template<typename T> bool operator== (const T rhs) const { return first == 0 && static_cast<T>(second) == rhs; }
template<typename T> bool operator!= (const T rhs) const { return first != 0 || static_cast<T>(second) != rhs; }
template<typename T> bool operator>= (const T rhs) const { return first != 0 && static_cast<T>(second) >= rhs; }
template<typename T> bool operator> (const T rhs) const { return first != 0 && static_cast<T>(second) > rhs; }
template<typename T> bool operator<= (const T rhs) const { return first == 0 && static_cast<T>(second) <= rhs; }
template<typename T> bool operator< (const T rhs) const { return first == 0 && static_cast<T>(second) > 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 operator< (const T rhs) const { return low == 0 && static_cast<T>(high) > rhs; }
template<typename T> explicit operator T() const { return static_cast<T>(second); }
operator UInt128() const { return *this; }
template<typename T> explicit operator T() const { return static_cast<T>(high); }
#if !__clang__
#pragma GCC diagnostic pop
#endif
UInt128 & operator= (const UInt64 rhs) { first = 0; second = rhs; return *this; }
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.first == 0 && a >= static_cast<T>(b.second); }
template<typename T> bool operator> (T a, const UInt128 & b) { return b.first == 0 && a > static_cast<T>(b.second); }
template<typename T> bool operator<= (T a, const UInt128 & b) { return b.first != 0 || a <= static_cast<T>(b.second); }
template<typename T> bool operator< (T a, const UInt128 & b) { return b.first != 0 || a < static_cast<T>(b.second); }
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); }
struct UInt128Hash
{
size_t operator()(UInt128 x) const
{
return CityHash_v1_0_2::Hash128to64({x.first, x.second});
return CityHash_v1_0_2::Hash128to64({x.low, x.high});
}
};
@ -76,8 +75,8 @@ struct UInt128HashCRC32
size_t operator()(UInt128 x) const
{
UInt64 crc = -1ULL;
crc = _mm_crc32_u64(crc, x.first);
crc = _mm_crc32_u64(crc, x.second);
crc = _mm_crc32_u64(crc, x.low);
crc = _mm_crc32_u64(crc, x.high);
return crc;
}
};
@ -91,7 +90,7 @@ struct UInt128HashCRC32 : public UInt128Hash {};
struct UInt128TrivialHash
{
size_t operator()(UInt128 x) const { return x.first; }
size_t operator()(UInt128 x) const { return x.low; }
};
@ -185,7 +184,7 @@ template <> struct hash<DB::UInt128>
{
size_t operator()(const DB::UInt128 & u) const
{
return std::hash<DB::UInt64>()(u.first) ^ std::hash<DB::UInt64>()(u.second);
return CityHash_v1_0_2::Hash128to64({u.low, u.high});
}
};

View File

@ -40,7 +40,7 @@ Block LimitByBlockInputStream::readImpl()
for (auto & column : column_ptrs)
column->updateHashWithValue(i, hash);
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
if (keys_counts[key]++ < group_size)
{

View File

@ -51,12 +51,12 @@ void parseUUID(const UInt8 * src36, UUID & uuid)
memcpy(&s[8], &src36[9], 4);
memcpy(&s[12], &src36[14], 4);
uuid.first = strtoull(s, nullptr, 16);
uuid.low = strtoull(s, nullptr, 16);
memcpy(&s[0], &src36[19], 4);
memcpy(&s[4], &src36[24], 12);
uuid.second = strtoull(s, nullptr, 16);
uuid.high = strtoull(s, nullptr, 16);
}
static void __attribute__((__noinline__)) throwAtAssertionFailed(const char * s, ReadBuffer & buf)

View File

@ -52,7 +52,7 @@ public:
SipHash hash;
hash.update(path_to_file.data(), path_to_file.size() + 1);
hash.update(reinterpret_cast<const char *>(&offset), sizeof(offset));
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
return key;
}

View File

@ -57,13 +57,13 @@ void formatUUID(const UUID & uuid, UInt8 * dst36)
dst36[18] = '-';
dst36[23] = '-';
snprintf(s, sizeof(s), "%016llx", static_cast<long long>(uuid.first));
snprintf(s, sizeof(s), "%016llx", static_cast<long long>(uuid.low));
memcpy(&dst36[0], &s, 8);
memcpy(&dst36[9], &s[8], 4);
memcpy(&dst36[14], &s[12], 4);
snprintf(s, sizeof(s), "%016llx", static_cast<long long>(uuid.second));
snprintf(s, sizeof(s), "%016llx", static_cast<long long>(uuid.high));
memcpy(&dst36[19], &s[0], 4);
memcpy(&dst36[24], &s[4], 12);

View File

@ -186,7 +186,7 @@ static inline UInt128 ALWAYS_INLINE hash128(
hash.update(keys[j].data, keys[j].size);
}
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
return key;
}
@ -202,7 +202,7 @@ static inline UInt128 ALWAYS_INLINE hash128(
for (size_t j = 0; j < keys_size; ++j)
key_columns[j]->updateHashWithValue(i, hash);
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
return key;
}

View File

@ -59,7 +59,7 @@ static Compiler::HashedKey getHash(const std::string & key)
hash.update(key.data(), key.size());
Compiler::HashedKey res;
hash.get128(res.first, res.second);
hash.get128(res.low, res.high);
return res;
}
@ -71,7 +71,7 @@ static std::string hashedKeyToFileName(Compiler::HashedKey hashed_key)
{
WriteBufferFromString out(file_name);
out << hashed_key.first << '_' << hashed_key.second;
out << hashed_key.low << '_' << hashed_key.high;
}
return file_name;

View File

@ -48,7 +48,7 @@ public:
SipHash hash;
hash.update(path_to_file.data(), path_to_file.size() + 1);
hash.get128(key.first, key.second);
hash.get128(key.low, key.high);
return key;
}