STL Memory Versioning
Public Types | Public Member Functions | List of all members
vs::vs_set< _Key, _Comp, _Strategy > Class Template Reference

A versioned mimic of a stl::set, suitable for multithread. More...

#include <vs_set.h>

Public Types

typedef Versioned< std::set< _Key, _Comp >, _Strategy > _Versioned
 
typedef std::set< _Key, _Comp >::iterator iterator
 
typedef std::set< _Key, _Comp >::size_type size_type
 

Public Member Functions

 vs_set (const _Comp &__comp=_Comp())
 Creates a vs_set with no elements. More...
 
 vs_set (std::initializer_list< _Key > __l, const _Comp &__comp=_Comp())
 Builds a vs_set from an initializer_list. More...
 
 vs_set (const vs_set &__vs_set)
 vs_set copy constructor More...
 
iterator begin () const noexcept
 begin constant iterator More...
 
iterator end () const noexcept
 end constant iterator More...
 
size_type size () const noexcept
 size of underlying set More...
 
bool contains (const _Key &__x)
 check if element is contained in set More...
 
iterator find (const _Key &__x) const
 find element in set More...
 
bool insert (const _Key &__x)
 Attempts to insert an element into the set. More...
 

Detailed Description

template<typename _Key, typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
class vs::vs_set< _Key, _Comp, _Strategy >

A versioned mimic of a stl::set, suitable for multithread.

Parameters
_KeyType of key objects.
_CompComparison function object type, defaults to less<_Key>.
_StrategyCustom strategy class for different merge behaviour

Definition at line 28 of file vs_set.h.

Member Typedef Documentation

◆ _Versioned

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
typedef Versioned<std::set<_Key, _Comp>, _Strategy> vs::vs_set< _Key, _Comp, _Strategy >::_Versioned

Definition at line 37 of file vs_set.h.

◆ iterator

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
typedef std::set<_Key, _Comp>::iterator vs::vs_set< _Key, _Comp, _Strategy >::iterator

Definition at line 38 of file vs_set.h.

◆ size_type

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
typedef std::set<_Key, _Comp>::size_type vs::vs_set< _Key, _Comp, _Strategy >::size_type

Definition at line 39 of file vs_set.h.

Constructor & Destructor Documentation

◆ vs_set() [1/3]

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
vs::vs_set< _Key, _Comp, _Strategy >::vs_set ( const _Comp &  __comp = _Comp())
inlineexplicit

Creates a vs_set with no elements.

Parameters
__compComparator to use.

Definition at line 53 of file vs_set.h.

54  : _v_s(std::set<_Key, _Comp>(__comp)) { }

◆ vs_set() [2/3]

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
vs::vs_set< _Key, _Comp, _Strategy >::vs_set ( std::initializer_list< _Key >  __l,
const _Comp &  __comp = _Comp() 
)
inline

Builds a vs_set from an initializer_list.

Parameters
__lAn initializer_list.
__compComparator to use.

Copy elements of the list to created vs_set. Lots of copies in process, but only one version gets added.

Definition at line 64 of file vs_set.h.

66  : _v_s(std::set<_Key, _Comp>(__l, __comp)) { }

◆ vs_set() [3/3]

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
vs::vs_set< _Key, _Comp, _Strategy >::vs_set ( const vs_set< _Key, _Comp, _Strategy > &  __vs_set)
inline

vs_set copy constructor

does not inherit versions history

Definition at line 73 of file vs_set.h.

74  : _v_s(__vs_set._v_s.Get()) { }

Member Function Documentation

◆ begin()

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
iterator vs::vs_set< _Key, _Comp, _Strategy >::begin ( ) const
inlinenoexcept

begin constant iterator

Returns a read-only (constant) iterator that points to the first element in the vs_set. Iteration is done in ascending order according to the keys.

Definition at line 91 of file vs_set.h.

92  { return _v_s.Get().begin(); }
const T & Get() const
Get the current value of the object in the current Revision.
Definition: versioned.h:186

◆ contains()

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
bool vs::vs_set< _Key, _Comp, _Strategy >::contains ( const _Key &  __x)
inline

check if element is contained in set

Definition at line 117 of file vs_set.h.

118  {
119  auto& _set = _v_s.Get();
120  return _set.find(__x) != _set.end();
121  }

◆ end()

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
iterator vs::vs_set< _Key, _Comp, _Strategy >::end ( ) const
inlinenoexcept

end constant iterator

Returns a read-only (constant) iterator that points one past the last element in the vs_set. Iteration is done in ascending order according to the keys.

Definition at line 102 of file vs_set.h.

103  { return _v_s.Get().end(); }

◆ find()

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
iterator vs::vs_set< _Key, _Comp, _Strategy >::find ( const _Key &  __x) const
inline

find element in set

Definition at line 127 of file vs_set.h.

128  { return _v_s.Get().find(__x); }

◆ insert()

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
bool vs::vs_set< _Key, _Comp, _Strategy >::insert ( const _Key &  __x)
inline

Attempts to insert an element into the set.

Parameters
__xElement to be inserted.
Returns
true if element was inserted

reasons not to insert:

  • this element is already present

Definition at line 144 of file vs_set.h.

145  {
146  return _v_s.Set(_v_s.Get(), [&](std::set<_Key, _Comp>& _set){return _set.insert(__x).second;});
147  }
bool Set(const T &v, const std::function< bool(T &)> &updater=nullptr)
Set new value of the object.
Definition: versioned.h:205

◆ size()

template<typename _Key , typename _Comp = std::less<_Key>, typename _Strategy = vs_set_strategy<_Key, _Comp>>
size_type vs::vs_set< _Key, _Comp, _Strategy >::size ( ) const
inlinenoexcept

size of underlying set

Definition at line 110 of file vs_set.h.

111  { return _v_s.Get().size(); }

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