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
/***************************************************************************
StaticEllpackIndexMultimap_impl.h - description
-------------------
begin : Sep 9, 2015
copyright : (C) 2015 by Tomas Oberhuber et al.
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#pragma once
#include <TNL/Experimental/Multimaps/StaticEllpackIndexMultimap.h>
namespace TNL {
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
StaticEllpackIndexMultimap()
: keysRange( 0 )
{
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
String
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
getType()
{
return String( "StaticEllpackIndexMultimap< ") +
String( TNL::getType< Index >() ) +
String( ", " ) +
Device :: getDeviceType() +
String( ", " ) +
String( TNL::getType< LocalIndexType >() ) +
String( " >" );
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
String
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
getTypeVirtual() const
{
return this->getType();
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
void
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
setKeysRange( const IndexType& keysRange )
{
TNL_ASSERT( keysRange >= 0, );
this->keysRange = keysRange;
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
const Index
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
getKeysRange() const
{
return this->keysRange;
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
bool
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
allocate()
{
return this->values.setSize( this->keysRange * ValuesCount );
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
typename StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::ValuesAccessorType
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
getValues( const IndexType& inputIndex )
{
TNL_ASSERT( inputIndex < this->getKeysRange(),
std::cerr << "inputIndex = " << inputIndex << std::endl
<< "this->getKeysRange() = " << this->getKeysRange() << std::endl; );
TNL_ASSERT( this->getKeysRange() * ValuesCount == this->values.getSize(),
std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl
<< "this->getKeysRange() = " << this->getKeysRange() << std::endl
<< "this->values.getSize() = " << this->values.getSize() << std::endl; );
return ValuesAccessorType( this->values.getData(), inputIndex );
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
typename StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::ConstValuesAccessorType
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
getValues( const IndexType& inputIndex ) const
{
TNL_ASSERT( inputIndex < this->getKeysRange(),
std::cerr << "inputIndex = " << inputIndex << std::endl
<< "this->getKeysRange() = " << this->getKeysRange() << std::endl; );
TNL_ASSERT( this->getKeysRange() * ValuesCount == this->values.getSize(),
std::cerr << "The map has not been reallocated after calling setKeysRange()." << std::endl
<< "this->getKeysRange() = " << this->getKeysRange() << std::endl
<< "this->values.getSize() = " << this->values.getSize() << std::endl; );
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
return ConstValuesAccessorType( this->values.getData(), inputIndex );
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
bool
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
operator==( const StaticEllpackIndexMultimap& other ) const
{
return ( this->keysRange == other.keysRange && this->values == other.values );
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
bool
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
save( File& file ) const
{
if( ! Object::save( file ) )
return false;
if( ! file.write( &this->keysRange ) )
return false;
if( ! this->values.save( file ) )
return false;
return true;
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
bool
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
load( File& file )
{
if( ! Object::load( file ) )
return false;
if( ! file.read( &this->keysRange ) )
return false;
if( ! this->values.load( file ) )
return false;
return true;
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
void
StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >::
print( std::ostream& str ) const
{
str << "[ ";
if( this->getKeysRange() > 0 )
{
str << this->getValues( 0 );
for( Index i = 1; i < this->getKeysRange(); i++ )
str << ",\n " << this->getValues( i );
}
str << " ]";
}
template< int ValuesCount,
typename Index,
typename Device,
typename LocalIndex >
std::ostream& operator << ( std::ostream& str, const StaticEllpackIndexMultimap< ValuesCount, Index, Device, LocalIndex >& multimap )
{
multimap.print( str );
return str;
}
} // namespace TNL