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)
8 : view_(&view), root_(key), sle_(view_->read(root_))
9{
10 if (sle_ != nullptr)
11 indexes_ = &sle_->getFieldV256(sfIndexes);
12}
13
14auto
16{
17 auto it = const_iterator(*view_, root_, root_);
18 if (sle_ != nullptr)
19 {
20 it.sle_ = sle_;
21 if (!indexes_->empty())
22 {
23 it.indexes_ = indexes_;
24 it.it_ = std::begin(*indexes_);
25 it.index_ = *it.it_;
26 }
27 }
28
29 return it;
30}
31
32auto
34{
36}
37
38bool
40{
41 if (view_ == nullptr || other.view_ == nullptr)
42 return false;
43
44 XRPL_ASSERT(
45 view_ == other.view_ && root_.key == other.root_.key,
46 "xrpl::const_iterator::operator== : views and roots are matching");
47 return page_.key == other.page_.key && index_ == other.index_;
48}
49
52{
53 XRPL_ASSERT(index_ != beast::zero, "xrpl::const_iterator::operator* : nonzero index");
54 if (!cache_)
56 return *cache_;
57}
58
61{
62 XRPL_ASSERT(index_ != beast::zero, "xrpl::const_iterator::operator++ : nonzero index");
63 if (++it_ != std::end(*indexes_))
64 {
65 index_ = *it_;
67 return *this;
68 }
69
70 return next_page();
71}
72
75{
76 XRPL_ASSERT(index_ != beast::zero, "xrpl::const_iterator::operator++(int) : nonzero index");
77 const_iterator tmp(*this);
78 ++(*this);
79 return tmp;
80}
81
84{
85 auto const next = sle_->getFieldU64(sfIndexNext);
86 if (next == 0)
87 {
89 index_ = beast::zero;
90 }
91 else
92 {
93 page_ = keylet::page(root_, next);
94 sle_ = view_->read(page_);
95 XRPL_ASSERT(sle_, "xrpl::const_iterator::next_page : non-null SLE");
96 indexes_ = &sle_->getFieldV256(sfIndexes);
97 if (indexes_->empty())
98 {
99 index_ = beast::zero;
100 }
101 else
102 {
104 index_ = *it_;
105 }
106 }
108 return *this;
109}
110
113{
114 return indexes_->size();
115}
116
117} // namespace xrpl
T begin(T... args)
std::optional< value_type > cache_
Definition Dir.h:104
std::size_t page_size()
Definition Dir.cpp:112
bool operator==(const_iterator const &other) const
Definition Dir.cpp:39
const_iterator & operator++()
Definition Dir.cpp:60
const_iterator & next_page()
Definition Dir.cpp:83
std::shared_ptr< SLE const > sle_
Definition Dir.h:105
std::vector< uint256 >::const_iterator it_
Definition Dir.h:107
reference operator*() const
Definition Dir.cpp:51
STVector256 const * indexes_
Definition Dir.h:106
value_type const & reference
Definition Dir.h:46
ReadView const * view_
Definition Dir.h:100
ReadView const * view_
Definition Dir.h:23
const_iterator begin() const
Definition Dir.cpp:15
const_iterator end() const
Definition Dir.cpp:33
STVector256 const * indexes_
Definition Dir.h:26
std::shared_ptr< SLE const > sle_
Definition Dir.h:25
Keylet root_
Definition Dir.h:24
Dir(ReadView const &, Keylet const &)
Definition Dir.cpp:7
A view into a ledger.
Definition ReadView.h:31
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:171
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Definition Indexes.cpp:342
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
uint256 key
Definition Keylet.h:20