2022-02-07 22:42:53 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/utils/common.h"
|
2022-02-07 20:40:28 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/tests.h"
|
2022-02-07 22:42:53 +01:00
|
|
|
|
2022-02-07 20:40:28 +01:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
TEST(FlatHashMap, basic) {
|
|
|
|
td::FlatHashMap<int, int> map;
|
|
|
|
map[1] = 2;
|
|
|
|
ASSERT_EQ(2, map[1]);
|
|
|
|
ASSERT_EQ(1, map.find(1)->first);
|
|
|
|
ASSERT_EQ(2, map.find(1)->second);
|
|
|
|
// ASSERT_EQ(1, map.find(1)->key());
|
|
|
|
// ASSERT_EQ(2, map.find(1)->value());
|
|
|
|
for (auto &kv : map) {
|
|
|
|
ASSERT_EQ(1, kv.first);
|
|
|
|
ASSERT_EQ(2, kv.second);
|
|
|
|
}
|
|
|
|
map.erase(map.find(1));
|
|
|
|
auto map_copy = map;
|
|
|
|
|
2022-02-07 22:42:53 +01:00
|
|
|
td::FlatHashMap<int, std::array<td::unique_ptr<td::string>, 20>> x;
|
2022-02-07 20:40:28 +01:00
|
|
|
auto y = std::move(x);
|
|
|
|
x[12];
|
|
|
|
x.erase(x.find(12));
|
2022-02-07 22:42:53 +01:00
|
|
|
}
|