#pragma once #include #include #include #include #include #include namespace DB::HashedDictionaryImpl { /// sparse_hash_map/sparse_hash_set template concept IsGoogleSparseHashTable = std::is_same_v>>; template concept IsStdMapCell = requires (V v) { v->first; v->second; }; /// HashMap/HashMapWithSavedHash/HashSet/HashMapWithSavedHash/PackedHashMap and their Cells template concept IsBuiltinHashTable = ( std::is_same_v, typename C::grower_type>> || std::is_same_v, typename C::grower_type>> || std::is_same_v, typename C::grower_type>> || std::is_same_v, typename C::grower_type>> || std::is_same_v, typename C::grower_type>> ); template concept IsBuiltinSetCell = requires (V v) { v.getKey(); }; template concept IsBuiltinMapCell = requires (V v) { v->getKey(); v->getMapped(); }; // NOLINTBEGIN(*) /// google::sparse_hash_map template auto getSetKeyFromCell(const T & value) { return value; } template auto getKeyFromCell(const T & value) requires (IsStdMapCell) { return value->first; } template auto getValueFromCell(const T & value) requires (IsStdMapCell) { return value->second; } /// size() - returns table size, without empty and deleted /// and since this is sparsehash, empty cells should not be significant, /// and since items cannot be removed from the dictionary, deleted is also not important. /// /// NOTE: for google::sparse_hash_set value_type is Key, for sparse_hash_map /// value_type is std::pair, and now we correctly takes into /// account padding in structures, if any. template auto getBufferSizeInBytes(const C & c) requires (IsGoogleSparseHashTable) { return c.size() * sizeof(typename C::value_type); } /// bucket_count() - Returns table size, that includes empty and deleted template auto getBufferSizeInCells(const C & c) requires (IsGoogleSparseHashTable) { return c.bucket_count(); } template auto resizeContainer(C & c, size_t size) requires (IsGoogleSparseHashTable) { return c.resize(size); } template auto clearContainer(C & c) requires (IsGoogleSparseHashTable) { return c.clear(); } /// HashMap template auto getSetKeyFromCell(const T & value) requires (IsBuiltinSetCell) { return value.getKey(); } template auto getKeyFromCell(const T & value) requires (IsBuiltinMapCell) { return value->getKey(); } template auto getValueFromCell(const T & value) requires (IsBuiltinMapCell) { return value->getMapped(); } template auto getBufferSizeInBytes(const C & c) requires (IsBuiltinHashTable) { return c.getBufferSizeInBytes(); } template auto getBufferSizeInCells(const C & c) requires (IsBuiltinHashTable) { return c.getBufferSizeInCells(); } template auto resizeContainer(C & c, size_t size) requires (IsBuiltinHashTable) { return c.reserve(size); } template void clearContainer(C & c) requires (IsBuiltinHashTable) { return c.clearAndShrink(); } // NOLINTEND(*) }