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
|
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
|
-
+
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
+
-
+
-
+
-
-
-
-
+
-
+
-
|
}
template< typename T >
class TempStorage
{
public:
template< typename TT >
auto& set( uint32_t cfgId, uint32_t index, TT&& x )
auto& set( uint32_t index, TT&& x )
{
auto [it, inserted] = m_storage.try_emplace( cfgId );
auto [it, inserted] = m_storage.try_emplace( index );
if( it->second.size() <= index )
it->second.resize( index + 1 );
it->second[index] = forward< TT >( x );
return it->second[index];
it->second = forward< TT >( x );
return it->second;
}
template< typename TT >
void setVec( uint32_t cfgId, TT&& x )
{
auto [it, inserted] = m_storage.try_emplace( cfgId );
it->second = forward< TT >( x );
}
const T* get( uint32_t cfgId, uint32_t index ) const
const T* get( uint32_t index ) const
{
auto it = m_storage.find( cfgId );
auto it = m_storage.find( index );
if( it == m_storage.end() )
return nullptr;
if( it->second.size() <= index )
return nullptr;
return &it->second[index];
return &it->second;
}
T* get( uint32_t cfgId, uint32_t index )
T* get( uint32_t index )
{
auto it = m_storage.find( cfgId );
auto it = m_storage.find( index );
if( it == m_storage.end() )
return nullptr;
if( it->second.size() <= index )
return nullptr;
return &it->second[index];
return &it->second;
}
private:
unordered_map< uint32_t, llvm::SmallVector< T, 8 > >
unordered_map< uint32_t, T > m_storage;
m_storage;
};
}
#endif
|