Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
UnorderedIndexedSet_impl.h - description
-------------------
begin : Feb 15, 2014
copyright : (C) 2014 by Tomas Oberhuber et al.
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#pragma once
#include <TNL/Containers/UnorderedIndexedSet.h>
namespace TNL {
namespace Containers {
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
void
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::clear()
{
map.clear();
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
typename UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::size_type
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::size() const
{
return map.size();
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
Index
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::insert( const Key& key )
{
auto iter = map.insert( value_type( key, size() ) ).first;
return iter->second;
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
std::pair< Index, bool >
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::try_insert( const Key& key )
{
auto pair = map.insert( value_type( key, size() ) );
return std::pair< Index, bool >{ pair.first->second, pair.second };
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
bool
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::find( const Key& key, Index& index ) const
{
auto iter = map.find( Key( key ) );
if( iter == map.end() )
return false;
index = iter->second.index;
return true;
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
typename UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::size_type
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::count( const Key& key ) const
{
return map.count( key );
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
typename UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::size_type
UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::erase( const Key& key )
{
return map.erase( key );
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
void UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >::print( std::ostream& str ) const
{
auto iter = map.begin();
str << iter->second.data;
iter++;
while( iter != map.end() )
{
str << ", " << iter->second.data;
iter++;
}
}
template< class Key,
class Index,
class Hash,
class KeyEqual,
class Allocator >
std::ostream& operator<<( std::ostream& str, UnorderedIndexedSet< Key, Index, Hash, KeyEqual, Allocator >& set )
{
set.print( str );
return str;
}
} // namespace Containers
} // namespace TNL