Krita Source Code Documentation
Loading...
Searching...
No Matches
ConcurrentMap< K, V, KT, VT >::Iterator Class Reference

#include <concurrent_map.h>

Public Member Functions

Key getKey () const
 
Value getValue () const
 
bool isValid () const
 
 Iterator ()=default
 
 Iterator (ConcurrentMap &map)
 
void next ()
 
void setMap (ConcurrentMap &map)
 

Private Attributes

Key m_hash
 
quint64 m_idx
 
Details::Tablem_table
 
Value m_value
 

Detailed Description

template<typename K, typename V, class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
class ConcurrentMap< K, V, KT, VT >::Iterator

Definition at line 300 of file concurrent_map.h.

Constructor & Destructor Documentation

◆ Iterator() [1/2]

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
ConcurrentMap< K, V, KT, VT >::Iterator::Iterator ( )
default

◆ Iterator() [2/2]

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
ConcurrentMap< K, V, KT, VT >::Iterator::Iterator ( ConcurrentMap & map)
inline

Definition at line 310 of file concurrent_map.h.

311 {
312 // Since we've forbidden concurrent inserts (for now), nonatomic would suffice here, but let's plan ahead:
313 m_table = map.m_root.load(Consume);
314 m_idx = -1;
315 next();
316 }
@ Consume
Definition atomic.h:58
Details::Table * m_table
Atomic< typename Details::Table * > m_root

References Consume, ConcurrentMap< K, V, KT, VT >::Iterator::m_idx, ConcurrentMap< K, V, KT, VT >::m_root, ConcurrentMap< K, V, KT, VT >::Iterator::m_table, and ConcurrentMap< K, V, KT, VT >::Iterator::next().

Member Function Documentation

◆ getKey()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Key ConcurrentMap< K, V, KT, VT >::Iterator::getKey ( ) const
inline

Definition at line 353 of file concurrent_map.h.

354 {
355 // Since we've forbidden concurrent inserts (for now), nonatomic would suffice here, but let's plan ahead:
356 return KeyTraits::dehash(m_hash);
357 }

References ConcurrentMap< K, V, KT, VT >::Iterator::m_hash.

◆ getValue()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Value ConcurrentMap< K, V, KT, VT >::Iterator::getValue ( ) const
inline

Definition at line 359 of file concurrent_map.h.

360 {
361 return m_value;
362 }

References ConcurrentMap< K, V, KT, VT >::Iterator::m_value.

◆ isValid()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
bool ConcurrentMap< K, V, KT, VT >::Iterator::isValid ( ) const
inline

Definition at line 345 of file concurrent_map.h.

346 {
347#ifdef SANITY_CHECK
348 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_value != Value(ValueTraits::Redirect), false);
349#endif
350 return m_value != Value(ValueTraits::NullValue);
351 }
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and ConcurrentMap< K, V, KT, VT >::Iterator::m_value.

◆ next()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
void ConcurrentMap< K, V, KT, VT >::Iterator::next ( )
inline

Definition at line 325 of file concurrent_map.h.

326 {
327 while (++m_idx <= m_table->sizeMask) {
328 // Index still inside range of table.
329 typename Details::CellGroup* group = m_table->getCellGroups() + (m_idx >> 2);
330 typename Details::Cell* cell = group->cells + (m_idx & 3);
331 m_hash = cell->hash.load(Relaxed);
332
333 if (m_hash != KeyTraits::NullHash) {
334 // Cell has been reserved.
335 m_value = cell->value.load(Relaxed);
336 if (m_value != Value(ValueTraits::NullValue))
337 return; // Yield this cell.
338 }
339 }
340 // That's the end of the map.
341 m_hash = KeyTraits::NullHash;
342 m_value = Value(ValueTraits::NullValue);
343 }
@ Relaxed
Definition atomic.h:57
T load(MemoryOrder memoryOrder) const
Definition atomic.h:89
Atomic< Hash > hash
Definition leapfrog.h:36
CellGroup * getCellGroups() const
Definition leapfrog.h:89
union Value::@1 value

References Leapfrog< Map >::CellGroup::cells, Leapfrog< Map >::Table::getCellGroups(), Leapfrog< Map >::Cell::hash, Atomic< T >::load(), ConcurrentMap< K, V, KT, VT >::Iterator::m_hash, ConcurrentMap< K, V, KT, VT >::Iterator::m_idx, ConcurrentMap< K, V, KT, VT >::Iterator::m_table, ConcurrentMap< K, V, KT, VT >::Iterator::m_value, Relaxed, and Leapfrog< Map >::Cell::value.

◆ setMap()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
void ConcurrentMap< K, V, KT, VT >::Iterator::setMap ( ConcurrentMap & map)
inline

Member Data Documentation

◆ m_hash

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Key ConcurrentMap< K, V, KT, VT >::Iterator::m_hash
private

Definition at line 305 of file concurrent_map.h.

◆ m_idx

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
quint64 ConcurrentMap< K, V, KT, VT >::Iterator::m_idx
private

Definition at line 304 of file concurrent_map.h.

◆ m_table

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Details::Table* ConcurrentMap< K, V, KT, VT >::Iterator::m_table
private

Definition at line 303 of file concurrent_map.h.

◆ m_value

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Value ConcurrentMap< K, V, KT, VT >::Iterator::m_value
private

Definition at line 306 of file concurrent_map.h.


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