Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2016-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_INDIRECTMAP_H6#define BITCOIN_INDIRECTMAP_H8#include <map>10template <class T>11struct DereferencingComparator { bool operator()(const T a, const T b) const { return *a < *b; } };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*> > in16* 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 address18* 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 the21* result of DereferencingComparator.22*/23template <class K, class T>24class indirectmap {25private:26typedef std::map<const K*, T, DereferencingComparator<const K*> > base;27base m;28public:29typedef typename base::iterator iterator;30typedef typename base::const_iterator const_iterator;31typedef typename base::size_type size_type;32typedef typename base::value_type value_type;34// passthrough (pointer interface)35std::pair<iterator, bool> insert(const value_type& value) { return m.insert(value); }37// pass address (value interface)38iterator find(const K& key) { return m.find(&key); }39const_iterator find(const K& key) const { return m.find(&key); }40iterator lower_bound(const K& key) { return m.lower_bound(&key); }41const_iterator lower_bound(const K& key) const { return m.lower_bound(&key); }42size_type erase(const K& key) { return m.erase(&key); }43size_type count(const K& key) const { return m.count(&key); }45// passthrough46bool empty() const { return m.empty(); }47size_type size() const { return m.size(); }48size_type max_size() const { return m.max_size(); }49void clear() { m.clear(); }50iterator begin() { return m.begin(); }51iterator end() { return m.end(); }52const_iterator begin() const { return m.begin(); }53const_iterator end() const { return m.end(); }54const_iterator cbegin() const { return m.cbegin(); }55const_iterator cend() const { return m.cend(); }56};58#endif // BITCOIN_INDIRECTMAP_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.