xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
ledger
Dir.cpp
1
#include <xrpl/ledger/Dir.h>
2
3
#include <xrpl/beast/utility/Zero.h>
4
#include <xrpl/beast/utility/instrumentation.h>
5
#include <xrpl/ledger/ReadView.h>
6
#include <xrpl/protocol/Indexes.h>
7
#include <xrpl/protocol/Keylet.h>
8
#include <xrpl/protocol/SField.h>
9
10
#include <
cstddef
>
11
#include <
iterator
>
12
#include <
optional
>
13
14
namespace
xrpl
{
15
16
using
const_iterator
=
Dir::ConstIterator
;
17
18
Dir::Dir
(
ReadView
const
& view,
Keylet
const
& key)
19
:
view_
(&view),
root_
(key),
sle_
(
view_
->read(
root_
))
20
{
21
if
(
sle_
!=
nullptr
)
22
indexes_
= &
sle_
->getFieldV256(sfIndexes);
23
}
24
25
auto
26
Dir::begin
() const ->
ConstIterator
27
{
28
auto
it =
ConstIterator
(*
view_
,
root_
,
root_
);
29
if
(
sle_
!=
nullptr
)
30
{
31
it.sle_ =
sle_
;
32
if
(!
indexes_
->empty())
33
{
34
it.indexes_ =
indexes_
;
35
it.it_ =
std::begin
(*
indexes_
);
36
it.index_ = *it.it_;
37
}
38
}
39
40
return
it;
41
}
42
43
auto
44
Dir::end
() const ->
ConstIterator
45
{
46
return
ConstIterator
(*
view_
,
root_
,
root_
);
47
}
48
49
bool
50
const_iterator::operator==
(
ConstIterator
const
& other)
const
51
{
52
if
(
view_
==
nullptr
|| other.
view_
==
nullptr
)
53
return
false
;
54
55
XRPL_ASSERT(
56
view_
== other.
view_
&&
root_
.key == other.
root_
.
key
,
57
"xrpl::Dir::ConstIterator::operator== : views and roots are matching"
);
58
return
page_
.key == other.
page_
.
key
&&
index_
== other.
index_
;
59
}
60
61
const_iterator::reference
62
const_iterator::operator*
()
const
63
{
64
XRPL_ASSERT(
index_
!=
beast::kZero
,
"xrpl::Dir::ConstIterator::operator* : nonzero index"
);
65
if
(!
cache_
)
66
cache_
=
view_
->read(
keylet::child
(
index_
));
67
return
*
cache_
;
68
}
69
70
const_iterator
&
71
const_iterator::operator++
()
72
{
73
XRPL_ASSERT(
index_
!=
beast::kZero
,
"xrpl::Dir::ConstIterator::operator++ : nonzero index"
);
74
if
(++
it_
!=
std::end
(*
indexes_
))
75
{
76
index_
= *
it_
;
77
cache_
= std::nullopt;
78
return
*
this
;
79
}
80
81
return
nextPage
();
82
}
83
84
const_iterator
85
const_iterator::operator++
(
int
)
86
{
87
XRPL_ASSERT(
88
index_
!=
beast::kZero
,
"xrpl::Dir::ConstIterator::operator++(int) : nonzero index"
);
89
ConstIterator
tmp(*
this
);
90
++(*this);
91
return
tmp;
92
}
93
94
const_iterator
&
95
const_iterator::nextPage
()
96
{
97
auto
const
next =
sle_
->getFieldU64(sfIndexNext);
98
if
(next == 0)
99
{
100
page_
.key =
root_
.key;
101
index_
=
beast::kZero
;
102
}
103
else
104
{
105
page_
=
keylet::page
(
root_
, next);
106
sle_
=
view_
->read(
page_
);
107
XRPL_ASSERT(
sle_
,
"xrpl::Dir::ConstIterator::nextPage : non-null SLE"
);
108
indexes_
= &
sle_
->getFieldV256(sfIndexes);
109
if
(
indexes_
->empty())
110
{
111
index_
=
beast::kZero
;
112
}
113
else
114
{
115
it_
=
std::begin
(*
indexes_
);
116
index_
= *
it_
;
117
}
118
}
119
cache_
= std::nullopt;
120
return
*
this
;
121
}
122
123
std::size_t
124
const_iterator::pageSize
()
125
{
126
return
indexes_
->size();
127
}
128
129
}
// namespace xrpl
std::begin
T begin(T... args)
xrpl::Dir::ConstIterator
Definition
Dir.h:51
xrpl::Dir::ConstIterator::pageSize
std::size_t pageSize()
Definition
Dir.cpp:124
xrpl::Dir::ConstIterator::root_
Keylet root_
Definition
Dir.h:104
xrpl::Dir::ConstIterator::nextPage
ConstIterator & nextPage()
Definition
Dir.cpp:95
xrpl::Dir::ConstIterator::it_
std::vector< UInt256 >::const_iterator it_
Definition
Dir.h:110
xrpl::Dir::ConstIterator::operator++
ConstIterator & operator++()
Definition
Dir.cpp:71
xrpl::Dir::ConstIterator::index_
UInt256 index_
Definition
Dir.h:106
xrpl::Dir::ConstIterator::sle_
SLE::const_pointer sle_
Definition
Dir.h:108
xrpl::Dir::ConstIterator::view_
ReadView const * view_
Definition
Dir.h:103
xrpl::Dir::ConstIterator::reference
value_type const & reference
Definition
Dir.h:55
xrpl::Dir::ConstIterator::page_
Keylet page_
Definition
Dir.h:105
xrpl::Dir::ConstIterator::ConstIterator
ConstIterator(ReadView const &view, Keylet const &root, Keylet const &page)
Definition
Dir.h:98
xrpl::Dir::ConstIterator::operator*
reference operator*() const
Definition
Dir.cpp:62
xrpl::Dir::ConstIterator::operator==
bool operator==(ConstIterator const &other) const
Definition
Dir.cpp:50
xrpl::Dir::ConstIterator::indexes_
STVector256 const * indexes_
Definition
Dir.h:109
xrpl::Dir::ConstIterator::cache_
std::optional< value_type > cache_
Definition
Dir.h:107
xrpl::Dir::view_
ReadView const * view_
Definition
Dir.h:32
xrpl::Dir::begin
ConstIterator begin() const
Definition
Dir.cpp:26
xrpl::Dir::end
ConstIterator end() const
Definition
Dir.cpp:44
xrpl::Dir::sle_
SLE::const_pointer sle_
Definition
Dir.h:34
xrpl::Dir::indexes_
STVector256 const * indexes_
Definition
Dir.h:35
xrpl::Dir::root_
Keylet root_
Definition
Dir.h:33
xrpl::Dir::Dir
Dir(ReadView const &, Keylet const &)
Definition
Dir.cpp:18
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
cstddef
std::end
T end(T... args)
iterator
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl::keylet::page
Keylet page(UInt256 const &root, std::uint64_t const index=0) noexcept
A page in a directory.
Definition
Indexes.cpp:409
xrpl::keylet::child
Keylet child(UInt256 const &key) noexcept
Any item that can be in an owner dir.
Definition
Indexes.cpp:226
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::const_iterator
Dir::ConstIterator const_iterator
Definition
Dir.cpp:16
optional
std::size_t
xrpl::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition
Keylet.h:20
xrpl::Keylet::key
UInt256 key
Definition
Keylet.h:21
Generated by
1.17.0