rippled
Loading...
Searching...
No Matches
RippleLineCache.h
1#pragma once
2
3#include <xrpld/app/ledger/Ledger.h>
4#include <xrpld/app/paths/TrustLine.h>
5
6#include <xrpl/basics/CountedObject.h>
7#include <xrpl/basics/hardened_hash.h>
8
9#include <cstddef>
10#include <mutex>
11#include <vector>
12
13namespace xrpl {
14
15// Used by Pathfinder
16class RippleLineCache final : public CountedObject<RippleLineCache>
17{
18public:
21
23 getLedger() const
24 {
25 return ledger_;
26 }
27
41 getRippleLines(AccountID const& accountID, LineDirection direction);
42
43private:
45
48
50
51 struct AccountKey final : public CountedObject<AccountKey>
52 {
56
57 AccountKey(AccountID const& account, LineDirection direction, std::size_t hash)
58 : account_(account), direction_(direction), hash_value_(hash)
59 {
60 }
61
62 AccountKey(AccountKey const& other) = default;
63
65 operator=(AccountKey const& other) = default;
66
67 bool
68 operator==(AccountKey const& lhs) const
69 {
70 return hash_value_ == lhs.hash_value_ && account_ == lhs.account_ && direction_ == lhs.direction_;
71 }
72
74 get_hash() const
75 {
76 return hash_value_;
77 }
78
79 struct Hash
80 {
81 Hash() = default;
82
84 operator()(AccountKey const& key) const noexcept
85 {
86 return key.get_hash();
87 }
88 };
89 };
90
91 // Use a shared_ptr so entries can be removed from the map safely.
92 // Even though a shared_ptr to a vector will take more memory just a vector,
93 // most accounts are not going to have any entries (estimated over 90%), so
94 // vectors will not need to be created for them. This should lead to far
95 // less memory usage overall.
98};
99
100} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Tracks the number of instances of an object.
std::shared_ptr< ReadView const > const & getLedger() const
hash_map< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
std::shared_ptr< ReadView const > ledger_
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
beast::Journal journal_
xrpl::hardened_hash hasher_
Seed functor once per construction.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:21
std::size_t operator()(AccountKey const &key) const noexcept
AccountKey & operator=(AccountKey const &other)=default
AccountKey(AccountKey const &other)=default
bool operator==(AccountKey const &lhs) const
AccountKey(AccountID const &account, LineDirection direction, std::size_t hash)