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