2014-04-28 01:48:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Common/HashTable/HashMap.h>
|
2015-07-23 09:39:21 +00:00
|
|
|
#include <DB/Common/HashTable/ClearableHashSet.h>
|
2014-04-28 01:48:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <typename Key, typename Mapped, typename Hash>
|
2015-07-23 09:39:21 +00:00
|
|
|
using ClearableHashMapCell = ClearableHashTableCell<Key, HashMapCell<Key, Mapped, Hash, ClearableHashSetState>>;
|
2014-04-28 01:48:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
|
|
|
typename Key,
|
|
|
|
typename Mapped,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
2014-05-03 16:03:49 +00:00
|
|
|
typename Grower = HashTableGrower<>,
|
2014-04-28 01:48:24 +00:00
|
|
|
typename Allocator = HashTableAllocator
|
|
|
|
>
|
2014-05-22 01:19:14 +00:00
|
|
|
class ClearableHashMap : public HashTable<Key, ClearableHashMapCell<Key, Mapped, Hash>, Hash, Grower, Allocator>
|
2014-04-28 01:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-05-22 01:19:14 +00:00
|
|
|
typedef Key key_type;
|
|
|
|
typedef Mapped mapped_type;
|
|
|
|
typedef typename ClearableHashMap::cell_type::value_type value_type;
|
|
|
|
|
|
|
|
mapped_type & operator[](Key x)
|
|
|
|
{
|
|
|
|
typename ClearableHashMap::iterator it;
|
|
|
|
bool inserted;
|
|
|
|
this->emplace(x, it, inserted);
|
|
|
|
|
|
|
|
if (inserted)
|
2015-03-07 01:03:14 +00:00
|
|
|
new(&it->second) mapped_type();
|
2014-05-22 01:19:14 +00:00
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2014-04-28 01:48:24 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
++this->version;
|
|
|
|
this->m_size = 0;
|
|
|
|
}
|
|
|
|
};
|