From 32a2ec00d1c69da03cbbf5d4c48b0551cee21543 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 24 Dec 2014 22:00:14 +0300 Subject: [PATCH] dbms: more scalable aggragator: preparation [#METR-2944]. --- .../DB/Common/HashTable/TwoLevelHashMap.h | 55 +++++++++++++++++++ .../DB/Interpreters/AggregationCommon.h | 1 + 2 files changed, 56 insertions(+) create mode 100644 dbms/include/DB/Common/HashTable/TwoLevelHashMap.h diff --git a/dbms/include/DB/Common/HashTable/TwoLevelHashMap.h b/dbms/include/DB/Common/HashTable/TwoLevelHashMap.h new file mode 100644 index 00000000000..0e9a4d0919c --- /dev/null +++ b/dbms/include/DB/Common/HashTable/TwoLevelHashMap.h @@ -0,0 +1,55 @@ +#pragma once + +#include +#include + + +template +< + typename Key, + typename Cell, + typename Hash = DefaultHash, + typename Grower = HashTableGrower<8>, + typename Allocator = HashTableAllocator +> +class TwoLevelHashMapTable : public TwoLevelHashTable > +{ +public: + typedef Key key_type; + typedef typename Cell::Mapped mapped_type; + typedef typename Cell::value_type value_type; + + mapped_type & operator[](Key x) + { + typename TwoLevelHashMapTable::iterator it; + bool inserted; + this->emplace(x, it, inserted); + + if (!__has_trivial_constructor(mapped_type) && inserted) + new(&it->second) mapped_type(); + + return it->second; + } +}; + + +template +< + typename Key, + typename Mapped, + typename Hash = DefaultHash, + typename Grower = HashTableGrower<8>, + typename Allocator = HashTableAllocator +> +using TwoLevelHashMap = TwoLevelHashMapTable, Hash, Grower, Allocator>; + + +template +< + typename Key, + typename Mapped, + typename Hash = DefaultHash, + typename Grower = HashTableGrower<8>, + typename Allocator = HashTableAllocator +> +using TwoLevelHashMapWithSavedHash = TwoLevelHashMapTable, Hash, Grower, Allocator>; diff --git a/dbms/include/DB/Interpreters/AggregationCommon.h b/dbms/include/DB/Interpreters/AggregationCommon.h index f1f56a81aa6..5d06d11c03a 100644 --- a/dbms/include/DB/Interpreters/AggregationCommon.h +++ b/dbms/include/DB/Interpreters/AggregationCommon.h @@ -10,6 +10,7 @@ #include #include #include +#include template <>