rippled
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 <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/paths/RippleState.h>
25 #include <ripple/basics/hardened_hash.h>
26 #include <cstddef>
27 #include <memory>
28 #include <mutex>
29 #include <vector>
30 
31 namespace ripple {
32 
33 // Used by Pathfinder
35 {
36 public:
38 
40  getLedger() const
41  {
42  return mLedger;
43  }
44 
46  getRippleLines(AccountID const& accountID);
47 
48 private:
50 
53 
54  struct AccountKey
55  {
58 
59  AccountKey(AccountID const& account, std::size_t hash)
60  : account_(account), hash_value_(hash)
61  {
62  }
63 
64  AccountKey(AccountKey const& other) = default;
65 
66  AccountKey&
67  operator=(AccountKey const& other) = default;
68 
69  bool
70  operator==(AccountKey const& lhs) const
71  {
72  return hash_value_ == lhs.hash_value_ && account_ == lhs.account_;
73  }
74 
76  get_hash() const
77  {
78  return hash_value_;
79  }
80 
81  struct Hash
82  {
83  explicit Hash() = default;
84 
86  operator()(AccountKey const& key) const noexcept
87  {
88  return key.get_hash();
89  }
90  };
91  };
92 
95 };
96 
97 } // namespace ripple
98 
99 #endif
ripple::RippleLineCache::mLedger
std::shared_ptr< ReadView const > mLedger
Definition: RippleLineCache.h:52
std::shared_ptr
STL class.
ripple::RippleLineCache::mLock
std::mutex mLock
Definition: RippleLineCache.h:49
ripple::RippleLineCache::AccountKey::hash_value_
std::size_t hash_value_
Definition: RippleLineCache.h:57
vector
ripple::RippleLineCache::AccountKey::AccountKey
AccountKey(AccountID const &account, std::size_t hash)
Definition: RippleLineCache.h:59
ripple::RippleLineCache::AccountKey::Hash::operator()
std::size_t operator()(AccountKey const &key) const noexcept
Definition: RippleLineCache.h:86
ripple::RippleLineCache
Definition: RippleLineCache.h:34
ripple::RippleLineCache::AccountKey
Definition: RippleLineCache.h:54
ripple::RippleLineCache::AccountKey::account_
AccountID account_
Definition: RippleLineCache.h:56
ripple::base_uint
Definition: base_uint.h:63
ripple::RippleLineCache::RippleLineCache
RippleLineCache(std::shared_ptr< ReadView const > const &l)
Definition: RippleLineCache.cpp:25
ripple::RippleLineCache::AccountKey::operator==
bool operator==(AccountKey const &lhs) const
Definition: RippleLineCache.h:70
cstddef
ripple::hardened_hash
Seed functor once per construction.
Definition: hardened_hash.h:96
ripple::RippleLineCache::AccountKey::get_hash
std::size_t get_hash() const
Definition: RippleLineCache.h:76
ripple::RippleLineCache::AccountKey::Hash::Hash
Hash()=default
ripple::RippleLineCache::AccountKey::operator=
AccountKey & operator=(AccountKey const &other)=default
memory
ripple::RippleLineCache::AccountKey::Hash
Definition: RippleLineCache.h:81
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RippleLineCache::getRippleLines
std::vector< RippleState::pointer > const & getRippleLines(AccountID const &accountID)
Definition: RippleLineCache.cpp:34
ripple::RippleLineCache::lines_
hash_map< AccountKey, std::vector< RippleState::pointer >, AccountKey::Hash > lines_
Definition: RippleLineCache.h:94
ripple::RippleLineCache::hasher_
ripple::hardened_hash hasher_
Definition: RippleLineCache.h:51
mutex
std::size_t
std::unordered_map
STL class.
ripple::RippleLineCache::getLedger
std::shared_ptr< ReadView const > const & getLedger() const
Definition: RippleLineCache.h:40