Fix swap(fixed_vector) usages.

This commit is contained in:
levlam 2022-02-21 05:49:59 +03:00
parent f0a2ccd0fb
commit c9c9a73499
4 changed files with 16 additions and 13 deletions

View File

@ -14,13 +14,13 @@
namespace td {
template <class KeyT, class ValueT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>>
//using FlatHashMap = FlatHashMapImpl<KeyT, ValueT, HashT, EqT>;
using FlatHashMap = FlatHashMapChunks<KeyT, ValueT, HashT, EqT>;
using FlatHashMap = FlatHashMapImpl<KeyT, ValueT, HashT, EqT>;
//using FlatHashMap = FlatHashMapChunks<KeyT, ValueT, HashT, EqT>;
//using FlatHashMap = std::unordered_map<KeyT, ValueT, HashT, EqT>;
template <class KeyT, class HashT = std::hash<KeyT>, class EqT = std::equal_to<KeyT>>
//using FlatHashSet = FlatHashSetImpl<KeyT, HashT, EqT>;
using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>;
using FlatHashSet = FlatHashSetImpl<KeyT, HashT, EqT>;
//using FlatHashSet = FlatHashSetChunks<KeyT, HashT, EqT>;
//using FlatHashSet = std::unordered_set<KeyT, HashT, EqT>;
} // namespace td

View File

@ -243,10 +243,9 @@ class FlatHashTableChunks {
return *this;
}
void swap(FlatHashTableChunks &other) noexcept {
using std::swap;
swap(nodes_, other.nodes_);
swap(chunks_, other.chunks_);
swap(used_nodes_, other.used_nodes_);
nodes_.swap(other.nodes_);
chunks_.swap(other.chunks_);
std::swap(used_nodes_, other.used_nodes_);
}
~FlatHashTableChunks() = default;
@ -493,7 +492,7 @@ class FlatHashTableChunks {
CHECK(new_size >= Chunk::CHUNK_SIZE);
fixed_vector<Node> old_nodes(new_size);
fixed_vector<Chunk> chunks(new_size / Chunk::CHUNK_SIZE);
std::swap(old_nodes, nodes_);
old_nodes.swap(nodes_);
chunks_ = std::move(chunks);
used_nodes_ = 0;

View File

@ -287,9 +287,8 @@ class FlatHashTable {
return *this;
}
void swap(FlatHashTable &other) noexcept {
using std::swap;
swap(nodes_, other.nodes_);
swap(used_nodes_, other.used_nodes_);
nodes_.swap(other.nodes_);
std::swap(used_nodes_, other.used_nodes_);
}
~FlatHashTable() = default;
@ -496,7 +495,7 @@ class FlatHashTable {
void resize(size_t new_size) {
fixed_vector<Node> old_nodes(new_size);
std::swap(old_nodes, nodes_);
old_nodes.swap(nodes_);
for (auto &old_node : old_nodes) {
if (old_node.empty()) {

View File

@ -71,4 +71,9 @@ class fixed_vector {
size_t size_{0};
};
template <class T>
void swap(fixed_vector<T> &lhs, fixed_vector<T> &rhs) {
lhs.swap(rhs);
}
} // namespace td