Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
CoinsViewCacheCursor Struct Reference

Cursor for iterating over the linked list of flagged entries in CCoinsViewCache. More...

#include <coins.h>

Public Member Functions

 CoinsViewCacheCursor (size_t &usage LIFETIMEBOUND, CoinsCachePair &sentinel LIFETIMEBOUND, CCoinsMap &map LIFETIMEBOUND, bool will_erase) noexcept
 If will_erase is not set, iterating through the cursor will erase spent coins from the map, and other coins will be unflagged (removing them from the linked list). More...
 
CoinsCachePairBegin () const noexcept
 
CoinsCachePairEnd () const noexcept
 
CoinsCachePairNextAndMaybeErase (CoinsCachePair &current) noexcept
 Return the next entry after current, possibly erasing current. More...
 
bool WillErase (CoinsCachePair &current) const noexcept
 

Private Attributes

size_t & m_usage
 
CoinsCachePairm_sentinel
 
CCoinsMapm_map
 
bool m_will_erase
 

Detailed Description

Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.

This is a helper struct to encapsulate the diverging logic between a non-erasing CCoinsViewCache::Sync and an erasing CCoinsViewCache::Flush. This allows the receiver of CCoinsView::BatchWrite to iterate through the flagged entries without knowing the caller's intent.

However, the receiver can still call CoinsViewCacheCursor::WillErase to see if the caller will erase the entry after BatchWrite returns. If so, the receiver can perform optimizations such as moving the coin out of the CCoinsCachEntry instead of copying it.

Definition at line 265 of file coins.h.

Constructor & Destructor Documentation

◆ CoinsViewCacheCursor()

CoinsViewCacheCursor::CoinsViewCacheCursor ( size_t &usage  LIFETIMEBOUND,
CoinsCachePair &sentinel  LIFETIMEBOUND,
CCoinsMap &map  LIFETIMEBOUND,
bool  will_erase 
)
inlinenoexcept

If will_erase is not set, iterating through the cursor will erase spent coins from the map, and other coins will be unflagged (removing them from the linked list).

If will_erase is set, the underlying map and linked list will not be modified, as the caller is expected to wipe the entire map anyway. This is an optimization compared to erasing all entries as the cursor iterates them when will_erase is set. Calling CCoinsMap::clear() afterwards is faster because a CoinsCachePair cannot be coerced back into a CCoinsMap::iterator to be erased, and must therefore be looked up again by key in the CCoinsMap before being erased.

Definition at line 274 of file coins.h.

Member Function Documentation

◆ Begin()

CoinsCachePair * CoinsViewCacheCursor::Begin ( ) const
inlinenoexcept

Definition at line 280 of file coins.h.

Here is the caller graph for this function:

◆ End()

CoinsCachePair * CoinsViewCacheCursor::End ( ) const
inlinenoexcept

Definition at line 281 of file coins.h.

Here is the caller graph for this function:

◆ NextAndMaybeErase()

CoinsCachePair * CoinsViewCacheCursor::NextAndMaybeErase ( CoinsCachePair current)
inlinenoexcept

Return the next entry after current, possibly erasing current.

Definition at line 284 of file coins.h.

Here is the caller graph for this function:

◆ WillErase()

bool CoinsViewCacheCursor::WillErase ( CoinsCachePair current) const
inlinenoexcept

Definition at line 300 of file coins.h.

Here is the caller graph for this function:

Member Data Documentation

◆ m_map

CCoinsMap& CoinsViewCacheCursor::m_map
private

Definition at line 304 of file coins.h.

◆ m_sentinel

CoinsCachePair& CoinsViewCacheCursor::m_sentinel
private

Definition at line 303 of file coins.h.

◆ m_usage

size_t& CoinsViewCacheCursor::m_usage
private

Definition at line 302 of file coins.h.

◆ m_will_erase

bool CoinsViewCacheCursor::m_will_erase
private

Definition at line 305 of file coins.h.


The documentation for this struct was generated from the following file: