rippled
Loading...
Searching...
No Matches
Dir.cpp
1#include <xrpl/ledger/Dir.h>
2
3namespace ripple {
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 "ripple::const_iterator::operator== : views and roots are matching");
47 return page_.key == other.page_.key && index_ == other.index_;
48}
49
52{
53 XRPL_ASSERT(
54 index_ != beast::zero,
55 "ripple::const_iterator::operator* : nonzero index");
56 if (!cache_)
58 return *cache_;
59}
60
63{
64 XRPL_ASSERT(
65 index_ != beast::zero,
66 "ripple::const_iterator::operator++ : nonzero index");
67 if (++it_ != std::end(*indexes_))
68 {
69 index_ = *it_;
71 return *this;
72 }
73
74 return next_page();
75}
76
79{
80 XRPL_ASSERT(
81 index_ != beast::zero,
82 "ripple::const_iterator::operator++(int) : nonzero index");
83 const_iterator tmp(*this);
84 ++(*this);
85 return tmp;
86}
87
90{
91 auto const next = sle_->getFieldU64(sfIndexNext);
92 if (next == 0)
93 {
95 index_ = beast::zero;
96 }
97 else
98 {
99 page_ = keylet::page(root_, next);
100 sle_ = view_->read(page_);
101 XRPL_ASSERT(sle_, "ripple::const_iterator::next_page : non-null SLE");
102 indexes_ = &sle_->getFieldV256(sfIndexes);
103 if (indexes_->empty())
104 {
105 index_ = beast::zero;
106 }
107 else
108 {
110 index_ = *it_;
111 }
112 }
114 return *this;
115}
116
119{
120 return indexes_->size();
121}
122
123} // namespace ripple
T begin(T... args)
bool operator==(const_iterator const &other) const
Definition Dir.cpp:39
const_iterator & next_page()
Definition Dir.cpp:89
std::vector< uint256 >::const_iterator it_
Definition Dir.h:108
reference operator*() const
Definition Dir.cpp:51
std::size_t page_size()
Definition Dir.cpp:118
ReadView const * view_
Definition Dir.h:101
value_type const & reference
Definition Dir.h:47
std::optional< value_type > cache_
Definition Dir.h:105
STVector256 const * indexes_
Definition Dir.h:107
const_iterator & operator++()
Definition Dir.cpp:62
std::shared_ptr< SLE const > sle_
Definition Dir.h:106
std::shared_ptr< SLE const > sle_
Definition Dir.h:26
const_iterator end() const
Definition Dir.cpp:33
ReadView const * view_
Definition Dir.h:24
STVector256 const * indexes_
Definition Dir.h:27
Dir(ReadView const &, Keylet const &)
Definition Dir.cpp:7
Keylet root_
Definition Dir.h:25
const_iterator begin() const
Definition Dir.cpp:15
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:171
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Definition Indexes.cpp:361
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