rippled
Loading...
Searching...
No Matches
Dir.cpp
1#include <xrpl/ledger/Dir.h>
2
3namespace xrpl {
4
6
7Dir::Dir(ReadView const& view, Keylet const& key) : view_(&view), root_(key), sle_(view_->read(root_))
8{
9 if (sle_ != nullptr)
10 indexes_ = &sle_->getFieldV256(sfIndexes);
11}
12
13auto
15{
16 auto it = const_iterator(*view_, root_, root_);
17 if (sle_ != nullptr)
18 {
19 it.sle_ = sle_;
20 if (!indexes_->empty())
21 {
22 it.indexes_ = indexes_;
23 it.it_ = std::begin(*indexes_);
24 it.index_ = *it.it_;
25 }
26 }
27
28 return it;
29}
30
31auto
33{
35}
36
37bool
39{
40 if (view_ == nullptr || other.view_ == nullptr)
41 return false;
42
43 XRPL_ASSERT(
44 view_ == other.view_ && root_.key == other.root_.key,
45 "xrpl::const_iterator::operator== : views and roots are matching");
46 return page_.key == other.page_.key && index_ == other.index_;
47}
48
51{
52 XRPL_ASSERT(index_ != beast::zero, "xrpl::const_iterator::operator* : nonzero index");
53 if (!cache_)
55 return *cache_;
56}
57
60{
61 XRPL_ASSERT(index_ != beast::zero, "xrpl::const_iterator::operator++ : nonzero index");
62 if (++it_ != std::end(*indexes_))
63 {
64 index_ = *it_;
66 return *this;
67 }
68
69 return next_page();
70}
71
74{
75 XRPL_ASSERT(index_ != beast::zero, "xrpl::const_iterator::operator++(int) : nonzero index");
76 const_iterator tmp(*this);
77 ++(*this);
78 return tmp;
79}
80
83{
84 auto const next = sle_->getFieldU64(sfIndexNext);
85 if (next == 0)
86 {
88 index_ = beast::zero;
89 }
90 else
91 {
92 page_ = keylet::page(root_, next);
93 sle_ = view_->read(page_);
94 XRPL_ASSERT(sle_, "xrpl::const_iterator::next_page : non-null SLE");
95 indexes_ = &sle_->getFieldV256(sfIndexes);
96 if (indexes_->empty())
97 {
98 index_ = beast::zero;
99 }
100 else
101 {
103 index_ = *it_;
104 }
105 }
107 return *this;
108}
109
112{
113 return indexes_->size();
114}
115
116} // namespace xrpl
T begin(T... args)
std::optional< value_type > cache_
Definition Dir.h:105
std::size_t page_size()
Definition Dir.cpp:111
bool operator==(const_iterator const &other) const
Definition Dir.cpp:38
const_iterator & operator++()
Definition Dir.cpp:59
const_iterator & next_page()
Definition Dir.cpp:82
std::shared_ptr< SLE const > sle_
Definition Dir.h:106
std::vector< uint256 >::const_iterator it_
Definition Dir.h:108
reference operator*() const
Definition Dir.cpp:50
STVector256 const * indexes_
Definition Dir.h:107
value_type const & reference
Definition Dir.h:47
ReadView const * view_
Definition Dir.h:101
ReadView const * view_
Definition Dir.h:24
const_iterator begin() const
Definition Dir.cpp:14
const_iterator end() const
Definition Dir.cpp:32
STVector256 const * indexes_
Definition Dir.h:27
std::shared_ptr< SLE const > sle_
Definition Dir.h:26
Keylet root_
Definition Dir.h:25
Dir(ReadView const &, Keylet const &)
Definition Dir.cpp:7
A view into a ledger.
Definition ReadView.h:32
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::size_t size() const
bool empty() const
T end(T... args)
T is_same_v
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Definition Indexes.cpp:166
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Definition Indexes.cpp:331
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
uint256 key
Definition Keylet.h:21