xentara-utils v2.0.3
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::lockFree::LockFreeTraversableMap< Element > Class Template Reference

A map that can be traversed without locking. More...

#include <xentara/utils/lockFree/LockFreeTraversableMap.hpp>

+ Inheritance diagram for xentara::utils::lockFree::LockFreeTraversableMap< Element >:

Classes

class  Iterator
 
class  Traverser
 

Public Types

using value_type = Element
 The value type.
 
using key_type = std::remove_cvref_t< InternalKey >
 The key type.
 
using mapped_type = Element
 The element type.
 
using iterator = Iterator
 An iterator.
 

Public Member Functions

 LockFreeTraversableMap ()=default
 Default constructor.
 
internal auto operator= (LockFreeTraversableMap &&other) noexcept -> LockFreeTraversableMap &
 Move-assignment operator.
 
template<typename Key , typename... Arguments>
requires std::constructible_from<Element, Arguments &&...>
auto try_emplace (const Key &key, Arguments &&...arguments) -> std::pair< iterator, bool >
 Emplaces an element with a certain key.
 
template<typename Key >
auto find (const Key &key) -> iterator
 Finds the element with a certain key.
 
auto erase (iterator position) -> iterator
 Removes the element an iterator points to.
 
auto empty () const noexcept -> bool
 Checks if the map is empty.
 
auto end () noexcept -> iterator
 Gets the end iterator.
 
auto traverse () const noexcept -> Traverser
 Gets a traverser for traversing the list in a lock-free manner.
 
template<typename KeyArgument >
auto find (const KeyArgument &key) -> iterator
 

Detailed Description

template<typename Element>
class xentara::utils::lockFree::LockFreeTraversableMap< Element >

A map that can be traversed without locking.

The key for the map must be part of Element, and there must be a function key(const Element &) findable by argument depended lookup that returns the key.

This class can be moved but not copied.

Member Typedef Documentation

◆ iterator

template<typename Element >
using xentara::utils::lockFree::LockFreeTraversableMap< Element >::iterator = Iterator

An iterator.

◆ key_type

template<typename Element >
using xentara::utils::lockFree::LockFreeTraversableMap< Element >::key_type = std::remove_cvref_t<InternalKey>

The key type.

◆ mapped_type

template<typename Element >
using xentara::utils::lockFree::LockFreeTraversableMap< Element >::mapped_type = Element

The element type.

◆ value_type

template<typename Element >
using xentara::utils::lockFree::LockFreeTraversableMap< Element >::value_type = Element

The value type.

Constructor & Destructor Documentation

◆ LockFreeTraversableMap()

template<typename Element >
xentara::utils::lockFree::LockFreeTraversableMap< Element >::LockFreeTraversableMap ( )
default

Default constructor.

Member Function Documentation

◆ empty()

template<typename Element >
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::empty ( ) const -> bool
noexcept

Checks if the map is empty.

Attention
This function is thread-synchronized with operations on a Traverser, but not with other functions like try_emplace() and erase(). An external lock must be used to synchronize with these functions.

◆ end()

template<typename Element >
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::end ( ) -> iterator
noexcept

Gets the end iterator.

Attention
This function is thread-synchronized with operations on a Traverser, but not with other functions like try_emplace() and erase(). An external lock must be used to synchronize with these functions.
Returns
An iterator that can be used to determine if find() found an element.

◆ erase()

template<typename Element >
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::erase ( iterator  position) -> iterator

Removes the element an iterator points to.

Attention
This function is thread-synchronized with operations on a Traverser, but not with other functions like try_emplace() and find(). An external lock must be used to synchronize with these functions.

◆ find() [1/2]

template<typename Element >
template<typename Key >
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::find ( const Key &  key) -> iterator

Finds the element with a certain key.

Attention
This function is thread-synchronized with operations on a Traverser, but not with other functions like try_emplace() and erase(). An external lock must be used to synchronize with these functions.
Parameters
keyThe key to look for.
Returns
The iterator, or end() if the key was not found

◆ find() [2/2]

template<typename Element >
template<typename KeyArgument >
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::find ( const KeyArgument &  key) -> iterator

◆ operator=()

template<typename Element >
internal auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::operator= ( LockFreeTraversableMap< Element > &&  other) -> LockFreeTraversableMap &
noexcept

Move-assignment operator.

◆ traverse()

template<typename Element >
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::traverse ( ) const -> Traverser
noexcept

Gets a traverser for traversing the list in a lock-free manner.

All operations on the traverser are automatically thread-synchronized with try_emplace(), find(), and erase().

◆ try_emplace()

template<typename Element >
requires std::constructible_from<Element, Arguments &&...>
template<typename Key , typename... Arguments>
requires std::constructible_from<Element, Arguments &&...>
auto xentara::utils::lockFree::LockFreeTraversableMap< Element >::try_emplace ( const Key &  key,
Arguments &&...  arguments 
) -> std::pair<iterator, bool>

Emplaces an element with a certain key.

Attention
This function is thread-synchronized with operations on a Traverser, but not with other functions like find() and erase(). An external lock must be used to synchronize with these functions.
Parameters
keyThe key that the element will have once it is constructed.
argumentsThe arguments to pass to the constructor if an element is constructed. Must construct an element with a key that compares equal to key.
Returns
An iterator to the element, together with a flag that denotes whether an element was emplaced (true) or an existing element returned (false).