ClickHouse/dbms/src/Interpreters/tests/hash_map3.cpp

92 lines
2.0 KiB
C++
Raw Normal View History

2014-02-02 10:42:56 +00:00
#include <iostream>
#define DBMS_HASH_MAP_DEBUG_RESIZES
#define DBMS_HASH_MAP_COUNT_COLLISIONS
#include <string.h>
#include <cstdlib>
2014-02-02 10:42:56 +00:00
#include <utility>
#include <Core/Types.h>
#include <Common/Exception.h>
2014-02-02 10:42:56 +00:00
#include <IO/ReadHelpers.h>
2014-02-03 03:09:50 +00:00
#include <common/StringRef.h>
2014-02-02 10:42:56 +00:00
#include <Common/HashTable/HashMap.h>
2014-02-02 10:42:56 +00:00
template
<
typename Key,
typename Mapped,
typename Hash = DefaultHash<Key>,
typename Grower = HashTableGrower<>,
typename Allocator = HashTableAllocator
2014-02-02 10:42:56 +00:00
>
class HashMapWithDump : public HashMap<Key, Mapped, Hash, Grower, Allocator>
2014-02-02 10:42:56 +00:00
{
public:
void dump() const
{
for (size_t i = 0; i < this->grower.bufSize(); ++i)
{
if (this->buf[i].isZero(*this))
std::cerr << "[ ]";
else
2019-08-01 15:57:02 +00:00
std::cerr << '[' << this->buf[i].getValue().first.data << ", " << this->buf[i].getValue().second << ']';
}
std::cerr << std::endl;
}
2014-02-02 10:42:56 +00:00
};
2015-02-13 04:28:31 +00:00
struct SimpleHash
2014-02-02 10:42:56 +00:00
{
size_t operator() (UInt64 x) const { return x; }
size_t operator() (StringRef x) const { return DB::parse<UInt64>(x.data); }
2014-02-02 10:42:56 +00:00
};
2014-05-03 16:03:49 +00:00
struct Grower : public HashTableGrower<2>
2014-02-02 10:42:56 +00:00
{
void increaseSize()
{
++size_degree;
}
2014-02-02 10:42:56 +00:00
};
2017-12-02 02:47:12 +00:00
int main(int, char **)
2014-02-02 10:42:56 +00:00
{
using Map = HashMapWithDump<
StringRef,
UInt64,
SimpleHash,
Grower,
HashTableAllocatorWithStackMemory<4 * 24>>;
Map map;
map.dump();
std::cerr << "size: " << map.size() << std::endl;
map[StringRef("1", 1)] = 1;
map.dump();
std::cerr << "size: " << map.size() << std::endl;
map[StringRef("9", 1)] = 1;
map.dump();
std::cerr << "size: " << map.size() << std::endl;
std::cerr << "Collisions: " << map.getCollisions() << std::endl;
map[StringRef("3", 1)] = 2;
map.dump();
std::cerr << "size: " << map.size() << std::endl;
std::cerr << "Collisions: " << map.getCollisions() << std::endl;
for (auto x : map)
A Proper lookup table that uses HashTable's API This is the first step of allowing heterogeneous cells in hash tables. performance test results are ``` 1. HashMap<UInt16, UInt8, TrivialHash, HashTableFixedGrower<16>>; 2. NewLookupMap<UInt16, UInt8> ResolutionWidth 30000 1 .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................223550276.46 ResolutionWidth 30000 2 .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................248772721.24 Best: 2 - 24877272124 ResolutionWidth 100000 1 ..........................................................................................................................................................................................................................................................238498413.99 ResolutionWidth 100000 2 ..........................................................................................................................................................................................................................................................261808889.98 Best: 2 - 26180888998 ResolutionWidth 300000 1 ...................................................................................239307348.81 ResolutionWidth 300000 2 ...................................................................................257592761.30 Best: 2 - 25759276130 ResolutionWidth 1000000 1 .........................240144759.26 ResolutionWidth 1000000 2 .........................257093531.91 Best: 2 - 25709353191 ResolutionWidth 5000000 1 .....241573260.35 ResolutionWidth 5000000 2 .....259314162.79 Best: 2 - 25931416279 ResolutionDepth 30000 1 .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................217108119.84 ResolutionDepth 30000 2 .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................249459504.41 Best: 2 - 24945950441 ResolutionDepth 100000 1 ..........................................................................................................................................................................................................................................................229065162.17 ResolutionDepth 100000 2 ..........................................................................................................................................................................................................................................................253769105.64 Best: 2 - 25376910564 ResolutionDepth 300000 1 ...................................................................................233079225.18 ResolutionDepth 300000 2 ...................................................................................256316273.78 Best: 2 - 25631627378 ResolutionDepth 1000000 1 .........................234184633.51 ResolutionDepth 1000000 2 .........................261100491.57 Best: 2 - 26110049157 ResolutionDepth 5000000 1 .....233118795.66 ResolutionDepth 5000000 2 .....252436160.41 Best: 2 - 25243616041 ```
2019-02-28 09:35:38 +00:00
std::cerr << x.getFirst().toString() << " -> " << x.getSecond() << std::endl;
return 0;
2014-02-02 10:42:56 +00:00
}