diff options
| author | levlam <levlam@telegram.org> | 2022-03-09 16:29:47 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2022-03-09 16:29:47 +0300 |
| commit | 8b897c7c5fa35a22dff82f45697e23188b18b05e (patch) | |
| tree | b4c54cafb23192664555418fd0c4059869068fb7 /tdutils/td/utils/SetNode.h | |
| parent | ea52727c2124409a5e793f7afcc7a942af78740b (diff) | |
Move MapNode and SetNode to separate classes.
Diffstat (limited to 'tdutils/td/utils/SetNode.h')
| -rw-r--r-- | tdutils/td/utils/SetNode.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tdutils/td/utils/SetNode.h b/tdutils/td/utils/SetNode.h new file mode 100644 index 000000000..8c54f2c1e --- /dev/null +++ b/tdutils/td/utils/SetNode.h @@ -0,0 +1,66 @@ +// +// 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; + using public_type = KeyT; + using second_type = KeyT; // TODO: remove second_type? + + KeyT first{}; + + const KeyT &key() const { + return first; + } + + KeyT &get_public() { + 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()); + DCHECK(!other.empty()); + first = other.first; + } + + bool empty() const { + return is_key_empty(first); + } + + void clear() { + first = KeyT(); + DCHECK(empty()); + } + + void emplace(KeyT key) { + first = std::move(key); + } +}; + +} // namespace td |
