rippled
Loading...
Searching...
No Matches
RippleLineCache.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_PATHS_RIPPLELINECACHE_H_INCLUDED
21#define RIPPLE_APP_PATHS_RIPPLELINECACHE_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24#include <xrpld/app/paths/TrustLine.h>
25
26#include <xrpl/basics/CountedObject.h>
27#include <xrpl/basics/hardened_hash.h>
28
29#include <cstddef>
30#include <mutex>
31#include <vector>
32
33namespace ripple {
34
35// Used by Pathfinder
36class RippleLineCache final : public CountedObject<RippleLineCache>
37{
38public:
39 explicit RippleLineCache(
43
45 getLedger() const
46 {
47 return ledger_;
48 }
49
63 getRippleLines(AccountID const& accountID, LineDirection direction);
64
65private:
67
70
72
73 struct AccountKey final : public CountedObject<AccountKey>
74 {
78
80 AccountID const& account,
81 LineDirection direction,
82 std::size_t hash)
83 : account_(account), direction_(direction), hash_value_(hash)
84 {
85 }
86
87 AccountKey(AccountKey const& other) = default;
88
90 operator=(AccountKey const& other) = default;
91
92 bool
93 operator==(AccountKey const& lhs) const
94 {
95 return hash_value_ == lhs.hash_value_ && account_ == lhs.account_ &&
97 }
98
100 get_hash() const
101 {
102 return hash_value_;
103 }
104
105 struct Hash
106 {
107 Hash() = default;
108
110 operator()(AccountKey const& key) const noexcept
111 {
112 return key.get_hash();
113 }
114 };
115 };
116
117 // Use a shared_ptr so entries can be removed from the map safely.
118 // Even though a shared_ptr to a vector will take more memory just a vector,
119 // most accounts are not going to have any entries (estimated over 90%), so
120 // vectors will not need to be created for them. This should lead to far
121 // less memory usage overall.
122 hash_map<
123 AccountKey,
125 AccountKey::Hash>
128};
129
130} // namespace ripple
131
132#endif
A generic endpoint for log messages.
Definition Journal.h:60
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:25
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:41
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