2022-03-09 14:29:47 +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)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/HashTableUtils.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class KeyT>
|
|
|
|
struct SetNode {
|
|
|
|
using public_key_type = KeyT;
|
2022-03-12 13:27:14 +01:00
|
|
|
using public_type = const KeyT;
|
2022-03-09 14:29:47 +01:00
|
|
|
using second_type = KeyT; // TODO: remove second_type?
|
|
|
|
|
|
|
|
KeyT first{};
|
|
|
|
|
|
|
|
const KeyT &key() const {
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
2022-03-12 13:27:14 +01:00
|
|
|
const KeyT &get_public() {
|
2022-03-09 14:29:47 +01:00
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetNode() = default;
|
|
|
|
explicit SetNode(KeyT key) : first(std::move(key)) {
|
|
|
|
}
|
|
|
|
SetNode(const SetNode &other) = delete;
|
|
|
|
SetNode &operator=(const SetNode &other) = delete;
|
|
|
|
SetNode(SetNode &&other) noexcept {
|
|
|
|
*this = std::move(other);
|
|
|
|
}
|
|
|
|
void operator=(SetNode &&other) noexcept {
|
|
|
|
DCHECK(empty());
|
|
|
|
DCHECK(!other.empty());
|
|
|
|
first = std::move(other.first);
|
|
|
|
other.first = KeyT{};
|
|
|
|
}
|
|
|
|
~SetNode() = default;
|
|
|
|
|
|
|
|
void copy_from(const SetNode &other) {
|
|
|
|
DCHECK(empty());
|
|
|
|
first = other.first;
|
2022-03-11 19:38:48 +01:00
|
|
|
DCHECK(!empty());
|
2022-03-09 14:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const {
|
2022-03-09 14:40:50 +01:00
|
|
|
return is_hash_table_key_empty(first);
|
2022-03-09 14:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
first = KeyT();
|
|
|
|
DCHECK(empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void emplace(KeyT key) {
|
|
|
|
first = std::move(key);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|