6 #ifndef KAGOME_CORE_STORAGE_TRIE_POLKADOT_TRIE_POLKADOT_TRIE_CURSOR_IMPL 7 #define KAGOME_CORE_STORAGE_TRIE_POLKADOT_TRIE_POLKADOT_TRIE_CURSOR_IMPL 37 [[nodiscard]]
static outcome::result<
38 std::unique_ptr<PolkadotTrieCursorImpl>>
40 const std::shared_ptr<const PolkadotTrie> &trie);
42 [[nodiscard]] outcome::result<bool>
seekFirst()
override;
44 [[nodiscard]] outcome::result<bool>
seek(
47 [[nodiscard]] outcome::result<bool>
seekLast()
override;
61 [[nodiscard]]
bool isValid()
const override;
63 [[nodiscard]] outcome::result<void>
next()
override;
65 [[nodiscard]] std::optional<common::Buffer>
key()
const override;
67 [[nodiscard]] std::optional<common::BufferConstRef>
value()
const override;
71 const TrieNode ¤t, gsl::span<const uint8_t> left_nibbles);
84 : parent{parent}, child_idx{child_idx} {}
95 : current_{state.current_}, path_{std::move(state.path_)} {}
99 path_ = std::move(state.path_);
110 [[nodiscard]] outcome::result<void> visitChild(uint8_t index,
114 if (isAtRoot())
return false;
115 current_ = &path_.back().parent;
121 return path_.empty();
125 BOOST_ASSERT_MSG(current_ !=
nullptr,
126 "SearchState implementation should guarantee it");
130 std::vector<TriePathEntry>
const &
getPath()
const {
154 -> outcome::result<SearchState>;
161 template <
typename Res>
162 outcome::result<Res>
safeAccess(outcome::result<Res> &&result) {
163 if (result.has_error()) {
166 return std::move(result);
168 #define SAFE_VOID_CALL(expr) OUTCOME_TRY(safeAccess((expr))); 170 #define SAFE_CALL(res, expr) OUTCOME_TRY(res, safeAccess((expr))); 172 std::shared_ptr<const PolkadotTrie>
trie_;
175 variant<UninitializedState, SearchState, InvalidState, ReachedEndState>;
183 #endif // KAGOME_CORE_STORAGE_TRIE_POLKADOT_TRIE_POLKADOT_TRIE_CURSOR_IMPL
~PolkadotTrieCursorImpl() override=default
Class represents arbitrary (including empty) byte buffer.
std::shared_ptr< const PolkadotTrie > trie_
std::variant< UninitializedState, SearchState, InvalidState, ReachedEndState > CursorState
outcome::result< void > seekLowerBoundInternal(const TrieNode ¤t, gsl::span< const uint8_t > left_nibbles)
outcome::result< bool > seekFirst() override
Same as std::begin(...);.
auto makeSearchStateAt(const common::BufferView &key) -> outcome::result< SearchState >
outcome::result< void > nextNodeWithValueInSubTree(const TrieNode &subtree_root)
outcome::result< void > seekLowerBound(const common::BufferView &key) override
outcome::result< Res > safeAccess(outcome::result< Res > &&result)
OUTCOME_HPP_DECLARE_ERROR(kagome::api, JRpcServerImpl::Error)
outcome::result< bool > seek(const common::BufferView &key) override
Find given key and seek iterator to this key.
outcome::result< bool > nextNodeWithValueInOuterTree()
std::vector< TriePathEntry > const & getPath() const
SearchState(SearchState &&state) noexcept
std::shared_ptr< soralog::Logger > Logger
const TrieNode & getCurrent() const
outcome::result< void > seekUpperBound(const common::BufferView &key) override
outcome::result< bool > seekLast() override
Same as std::rbegin(...);, e.g. points to the last valid element.
PolkadotTrieCursorImpl(std::shared_ptr< const PolkadotTrie > trie)
bool isValid() const override
Is the cursor in a valid state?
const BranchNode & parent
SearchState(const TrieNode &root)
outcome::result< const TrieNode * > visitChildWithMinIdx(const TrieNode &node, uint8_t min_idx=0)
std::vector< TriePathEntry > path_
const TrieNode * current_
TriePathEntry(const BranchNode &parent, uint8_t child_idx)
common::Buffer collectKey() const
std::optional< common::BufferConstRef > value() const override
Getter for value of the element currently pointed at.
static outcome::result< std::unique_ptr< PolkadotTrieCursorImpl > > createAt(const common::BufferView &key, const std::shared_ptr< const PolkadotTrie > &trie)
outcome::result< void > next() override
Make step forward.
std::optional< common::Buffer > key() const override
Getter for the key of the element currently pointed at.
SearchState & operator=(SearchState &&state) noexcept