Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
indirectmap.h
Go to the documentation of this file.
1
// Copyright (c) 2016-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_INDIRECTMAP_H
6
#define BITCOIN_INDIRECTMAP_H
7
8
#include <map>
9
10
template
<
class
T>
11
struct
DereferencingComparator
{
bool
operator()
(
const
T
a,
const
T
b)
const
{
return
*a < *b; } };
12
13
/* Map whose keys are pointers, but are compared by their dereferenced values.
14
*
15
* Differs from a plain std::map<const K*, T, DereferencingComparator<K*> > in
16
* that methods that take a key for comparison take a K rather than taking a K*
17
* (taking a K* would be confusing, since it's the value rather than the address
18
* of the object for comparison that matters due to the dereferencing comparator).
19
*
20
* Objects pointed to by keys must not be modified in any way that changes the
21
* result of DereferencingComparator.
22
*/
23
template
<
class
K,
class
T>
24
class
indirectmap
{
25
private
:
26
typedef
std::map<const K*, T, DereferencingComparator<const K*> >
base
;
27
base
m
;
28
public
:
29
typedef
typename
base::iterator
iterator
;
30
typedef
typename
base::const_iterator
const_iterator
;
31
typedef
typename
base::size_type
size_type
;
32
typedef
typename
base::value_type
value_type
;
33
34
// passthrough (pointer interface)
35
std::pair<iterator, bool>
insert
(
const
value_type
& value) {
return
m
.insert(value); }
36
37
// pass address (value interface)
38
iterator
find
(
const
K
& key) {
return
m
.find(&key); }
39
const_iterator
find
(
const
K
& key)
const
{
return
m
.find(&key); }
40
iterator
lower_bound
(
const
K
& key) {
return
m
.lower_bound(&key); }
41
const_iterator
lower_bound
(
const
K
& key)
const
{
return
m
.lower_bound(&key); }
42
size_type
erase
(
const
K
& key) {
return
m
.erase(&key); }
43
size_type
count
(
const
K
& key)
const
{
return
m
.count(&key); }
44
45
// passthrough
46
bool
empty
()
const
{
return
m
.empty(); }
47
size_type
size
()
const
{
return
m
.size(); }
48
size_type
max_size
()
const
{
return
m
.max_size(); }
49
void
clear
() {
m
.clear(); }
50
iterator
begin
() {
return
m
.begin(); }
51
iterator
end
() {
return
m
.end(); }
52
const_iterator
begin
()
const
{
return
m
.begin(); }
53
const_iterator
end
()
const
{
return
m
.end(); }
54
const_iterator
cbegin
()
const
{
return
m
.cbegin(); }
55
const_iterator
cend
()
const
{
return
m
.cend(); }
56
};
57
58
#endif
// BITCOIN_INDIRECTMAP_H
indirectmap
Definition
indirectmap.h:24
indirectmap::lower_bound
iterator lower_bound(const K &key)
Definition
indirectmap.h:40
indirectmap::cbegin
const_iterator cbegin() const
Definition
indirectmap.h:54
indirectmap::const_iterator
base::const_iterator const_iterator
Definition
indirectmap.h:30
indirectmap::empty
bool empty() const
Definition
indirectmap.h:46
indirectmap::begin
iterator begin()
Definition
indirectmap.h:50
indirectmap::size
size_type size() const
Definition
indirectmap.h:47
indirectmap::m
base m
Definition
indirectmap.h:27
indirectmap::iterator
base::iterator iterator
Definition
indirectmap.h:29
indirectmap::find
iterator find(const K &key)
Definition
indirectmap.h:38
indirectmap::cend
const_iterator cend() const
Definition
indirectmap.h:55
indirectmap::base
std::map< const K *, T, DereferencingComparator< const K * > > base
Definition
indirectmap.h:26
indirectmap::lower_bound
const_iterator lower_bound(const K &key) const
Definition
indirectmap.h:41
indirectmap::max_size
size_type max_size() const
Definition
indirectmap.h:48
indirectmap::erase
size_type erase(const K &key)
Definition
indirectmap.h:42
indirectmap::value_type
base::value_type value_type
Definition
indirectmap.h:32
indirectmap::end
const_iterator end() const
Definition
indirectmap.h:53
indirectmap::insert
std::pair< iterator, bool > insert(const value_type &value)
Definition
indirectmap.h:35
indirectmap::end
iterator end()
Definition
indirectmap.h:51
indirectmap::size_type
base::size_type size_type
Definition
indirectmap.h:31
indirectmap::count
size_type count(const K &key) const
Definition
indirectmap.h:43
indirectmap::clear
void clear()
Definition
indirectmap.h:49
indirectmap::find
const_iterator find(const K &key) const
Definition
indirectmap.h:39
indirectmap::begin
const_iterator begin() const
Definition
indirectmap.h:52
T
#define T(expected, seed, data)
ByteUnit::K
@ K
Definition
strencodings.h:47
DereferencingComparator
Definition
indirectmap.h:11
DereferencingComparator::operator()
bool operator()(const T a, const T b) const
Definition
indirectmap.h:11
Generated on
for Bitcoin Core by
1.17.0