volatile_set.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class Key, class Hash, class Pred >
6 {
7  if( this->iterators.size() )
8  this->toinsert.insert( val );
9  else
10  this->items.insert( val );
11 }
12 
13 template< class Key, class Hash, class Pred >
15 {
16  this->toinsert.erase( val );
17 
18  auto it = this->items.find( val );
19 
20  if( it == this->items.end() )
21  return;
22 
23  for( auto & iter : this->iterators )
24  if( iter == it )
25  ++iter;
26 
27  this->items.erase( val );
28 }
29 
30 template< class Key, class Hash, class Pred >
31 void volatile_set< Key, Hash, Pred >::foreach( std::function< void( Key const & ) > const & fun )
32 {
33  auto & it = this->lock_begin();
34 
35  while( it != this->items.end() )
36  {
37  Key const & item = *it;
38  ++it;
39  fun( item );
40  }
41 
42  this->unlock();
43 }
44 
45 template< class Key, class Hash, class Pred >
47 {
48  this->iterators.push_back( this->items.begin() );
49  return this->iterators.back();
50 }
51 
52 
53 template< class Key, class Hash, class Pred >
55 {
56  this->iterators.push_back( this->items.find( val ) );
57  return this->iterators.back();
58 }
59 
60 template< class Key, class Hash, class Pred >
62 {
63  this->iterators.pop_back();
64 
65  if( this->iterators.empty() )
66  {
67  this->items.insert( this->toinsert.begin(), this->toinsert.end() );
68  this->toinsert.clear();
69  }
70 }
71 
72 template< class Key, class Hash, class Pred >
74 {
75  return this->items.end();
76 }
77 
78 template< class Key, class Hash, class Pred >
80 {
81  return this->items.count( val ) || this->toinsert.count( val );
82 }
83 
84 template< class Key, class Hash, class Pred >
86 {
87  return this->items.size();
88 }
89 
90 
91 template< class Key, class Hash, class Pred >
93 {
94  return this->items.empty();
95 }
96 
97 }