mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-23 18:20:50 +00:00
Applied clang-format [#CLICKHOUSE-2].
This commit is contained in:
parent
39ddcf1c74
commit
2b67782845
@ -1,10 +1,10 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <string>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <common/StringRef.h>
|
|
||||||
#include <Common/SpaceSaving.h>
|
#include <Common/SpaceSaving.h>
|
||||||
|
#include <common/StringRef.h>
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
@ -14,7 +14,8 @@ int main(int argc, char ** argv)
|
|||||||
|
|
||||||
/* Test biased insertion */
|
/* Test biased insertion */
|
||||||
|
|
||||||
for (int i = 0; i < 200; ++i) {
|
for (int i = 0; i < 200; ++i)
|
||||||
|
{
|
||||||
first.insert(i);
|
first.insert(i);
|
||||||
int k = i % 5; // Bias towards 0-4
|
int k = i % 5; // Bias towards 0-4
|
||||||
first.insert(k);
|
first.insert(k);
|
||||||
@ -23,40 +24,52 @@ int main(int argc, char ** argv)
|
|||||||
/* Test whether the biased elements are retained */
|
/* Test whether the biased elements are retained */
|
||||||
|
|
||||||
std::map<int, UInt64> expect;
|
std::map<int, UInt64> expect;
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i)
|
||||||
|
{
|
||||||
expect[i] = 41;
|
expect[i] = 41;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto x : first.topK(5)) {
|
for (auto x : first.topK(5))
|
||||||
if (expect[x.key] != x.count) {
|
{
|
||||||
|
if (expect[x.key] != x.count)
|
||||||
|
{
|
||||||
std::cerr << "key: " << x.key << " value: " << x.count << " expected: " << expect[x.key] << std::endl;
|
std::cerr << "key: " << x.key << " value: " << x.count << " expected: " << expect[x.key] << std::endl;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::cout << "key: " << x.key << " value: " << x.count << std::endl;
|
std::cout << "key: " << x.key << " value: " << x.count << std::endl;
|
||||||
}
|
}
|
||||||
expect.erase(x.key);
|
expect.erase(x.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expect.empty()) {
|
if (!expect.empty())
|
||||||
|
{
|
||||||
std::cerr << "expected to find all heavy hitters" << std::endl;
|
std::cerr << "expected to find all heavy hitters" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create another table and test merging */
|
/* Create another table and test merging */
|
||||||
|
|
||||||
Cont second(10);
|
Cont second(10);
|
||||||
for (int i = 0; i < 200; ++i) {
|
for (int i = 0; i < 200; ++i)
|
||||||
|
{
|
||||||
first.insert(i);
|
first.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i)
|
||||||
|
{
|
||||||
expect[i] = 42;
|
expect[i] = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
first.merge(second);
|
first.merge(second);
|
||||||
|
|
||||||
for (auto x : first.topK(5)) {
|
for (auto x : first.topK(5))
|
||||||
if (expect[x.key] != x.count) {
|
{
|
||||||
|
if (expect[x.key] != x.count)
|
||||||
|
{
|
||||||
std::cerr << "key: " << x.key << " value: " << x.count << " expected: " << expect[x.key] << std::endl;
|
std::cerr << "key: " << x.key << " value: " << x.count << " expected: " << expect[x.key] << std::endl;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::cout << "key: " << x.key << " value: " << x.count << std::endl;
|
std::cout << "key: " << x.key << " value: " << x.count << std::endl;
|
||||||
}
|
}
|
||||||
expect.erase(x.key);
|
expect.erase(x.key);
|
||||||
@ -69,7 +82,8 @@ int main(int argc, char ** argv)
|
|||||||
using Cont = DB::SpaceSaving<StringRef, StringRefHash>;
|
using Cont = DB::SpaceSaving<StringRef, StringRefHash>;
|
||||||
Cont cont(10);
|
Cont cont(10);
|
||||||
|
|
||||||
for (int i = 0; i < 400; ++i) {
|
for (int i = 0; i < 400; ++i)
|
||||||
|
{
|
||||||
cont.insert(std::to_string(i));
|
cont.insert(std::to_string(i));
|
||||||
cont.insert(std::to_string(i % 5)); // Bias towards 0-4
|
cont.insert(std::to_string(i % 5)); // Bias towards 0-4
|
||||||
}
|
}
|
||||||
@ -77,21 +91,27 @@ int main(int argc, char ** argv)
|
|||||||
// The hashing is going to be more lossy
|
// The hashing is going to be more lossy
|
||||||
// Expect at least ~ 10% count
|
// Expect at least ~ 10% count
|
||||||
std::map<std::string, UInt64> expect;
|
std::map<std::string, UInt64> expect;
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i)
|
||||||
|
{
|
||||||
expect[std::to_string(i)] = 38;
|
expect[std::to_string(i)] = 38;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto x : cont.topK(5)) {
|
for (auto x : cont.topK(5))
|
||||||
|
{
|
||||||
auto key = x.key.toString();
|
auto key = x.key.toString();
|
||||||
if (x.count < expect[key]) {
|
if (x.count < expect[key])
|
||||||
|
{
|
||||||
std::cerr << "key: " << key << " value: " << x.count << " expected: " << expect[key] << std::endl;
|
std::cerr << "key: " << key << " value: " << x.count << " expected: " << expect[key] << std::endl;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::cout << "key: " << key << " value: " << x.count << std::endl;
|
std::cout << "key: " << key << " value: " << x.count << std::endl;
|
||||||
}
|
}
|
||||||
expect.erase(key);
|
expect.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expect.empty()) {
|
if (!expect.empty())
|
||||||
|
{
|
||||||
std::cerr << "expected to find all heavy hitters" << std::endl;
|
std::cerr << "expected to find all heavy hitters" << std::endl;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user