Newer
Older
/***************************************************************************
EllpackIndexMultimapValues_impl.h - description
-------------------
begin : Sep 10, 2015
copyright : (C) 2015 by Tomas Oberhuber et al.
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#include "EllpackIndexMultimapValues.h"
#include <TNL/Assert.h>
namespace Containers {
namespace Multimaps {
typename LocalIndex,
int step >
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
EllpackIndexMultimapValues()
Jakub Klinkovský
committed
: values( nullptr ), valuesCount( nullptr ), allocatedSize( 0 )
typename LocalIndex,
int step >
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
EllpackIndexMultimapValues( EllpackIndexMultimapValues&& other )
Jakub Klinkovský
committed
: values( other.values ), valuesCount( other.valuesCount ), allocatedSize( other.allocatedSize )
Jakub Klinkovský
committed
{
other.values = nullptr;
Jakub Klinkovský
committed
other.valuesCount = nullptr;
Jakub Klinkovský
committed
other.allocatedSize = 0;
}
template< typename Index,
typename Device,
typename LocalIndex,
int step >
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
EllpackIndexMultimapValues( IndexType* values,
ValuesCountType* valuesCount,
const LocalIndexType& allocatedSize )
: values( values ), valuesCount( valuesCount ), allocatedSize( allocatedSize )
{
TNL_ASSERT( *(this->valuesCount) <= allocatedSize, );
}
template< typename Index,
typename Device,
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >&
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator=( const EllpackIndexMultimapValues& other )
Jakub Klinkovský
committed
{
TNL_ASSERT( this->getAllocatedSize() >= other.getSize(), );
this->setSize( other.getSize() );
Jakub Klinkovský
committed
if( this->values != other.values ) {
for( LocalIndexType i = 0; i < this->getSize(); i++ )
this->setValue( i, other[ i ] );
}
return *this;
}
template< typename Index,
typename Device,
typename LocalIndex,
int step >
template< typename Index_, typename LocalIndex_, int step_ >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >&
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator=( const EllpackIndexMultimapValues< Index_, Device, LocalIndex_, step_ >& other )
{
TNL_ASSERT( this->getAllocatedSize() >= other.getSize(), );
this->setSize( other.getSize() );
for( LocalIndexType i = 0; i < this->getSize(); i++ )
this->setValue( i, other[ i ] );
return *this;
}
Jakub Klinkovský
committed
template< typename Index,
typename Device,
typename LocalIndex,
int step >
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >&
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator=( EllpackIndexMultimapValues&& other )
Jakub Klinkovský
committed
{
this->values = other.values;
Jakub Klinkovský
committed
this->valuesCount = other.valuesCount;
Jakub Klinkovský
committed
this->allocatedSize = other.allocatedSize;
other.values = nullptr;
Jakub Klinkovský
committed
other.valuesCount = nullptr;
Jakub Klinkovský
committed
other.allocatedSize = 0;
return *this;
}
template< typename Index,
typename Device,
typename LocalIndex,
int step >
__cuda_callable__
Jakub Klinkovský
committed
void
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
bind( const EllpackIndexMultimapValues& other )
Jakub Klinkovský
committed
{
this->values = other.values;
Jakub Klinkovský
committed
this->valuesCount = other.valuesCount;
Jakub Klinkovský
committed
this->allocatedSize = other.allocatedSize;
}
template< typename Index,
typename Device,
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
Jakub Klinkovský
committed
setSize( const LocalIndexType& size )
{
TNL_ASSERT( this->valuesCount,
std::cerr << "Uninitialized 'valuesCount' pointer in EllpackIndexMultimapValues." << std::endl; );
TNL_ASSERT( size >= 0 && size <= this->allocatedSize,
std::cerr << "size = " << size << ", allocatedSize = " << this->allocatedSize << std::endl; );
Jakub Klinkovský
committed
*valuesCount = size;
Jakub Klinkovský
committed
}
template< typename Index,
typename Device,
typename LocalIndex,
int step >
__cuda_callable__
Jakub Klinkovský
committed
LocalIndex
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
Jakub Klinkovský
committed
getSize() const
Jakub Klinkovský
committed
if( ! valuesCount )
Jakub Klinkovský
committed
return 0;
Jakub Klinkovský
committed
return *valuesCount;
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
Jakub Klinkovský
committed
getAllocatedSize() const
Jakub Klinkovský
committed
return this->allocatedSize;
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
Jakub Klinkovský
committed
setValue( const LocalIndexType& portIndex,
const IndexType& value )
TNL_ASSERT( portIndex < this->getSize(),
std::cerr << " portIndex = " << portIndex
<< " getSize() = " << this->getSize()
<< std::endl );
this->values[ portIndex * step ] = value;
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
Jakub Klinkovský
committed
getValue( const LocalIndexType& portIndex ) const
TNL_ASSERT( portIndex < this->getSize(),
std::cerr << " portIndex = " << portIndex
<< " getSize() = " << this->getSize()
<< std::endl );
return this->values[ portIndex * step ];
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator[]( const LocalIndexType& portIndex )
TNL_ASSERT( portIndex < this->getSize(),
std::cerr << " portIndex = " << portIndex
<< " getSize() = " << this->getSize()
<< std::endl );
return this->values[ portIndex * step ];
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator[]( const LocalIndexType& portIndex ) const
TNL_ASSERT( portIndex < this->getSize(),
std::cerr << " portIndex = " << portIndex
<< " getSize() = " << this->getSize()
<< std::endl );
return this->values[ portIndex * step ];
template< typename Index,
typename Device,
typename LocalIndex,
int step >
__cuda_callable__
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator==( const EllpackIndexMultimapValues& other ) const
{
if( this->getSize() != other.getSize() )
return false;
for( LocalIndexType i = 0; i < this->getSize(); i++ )
if( this->operator[]( i ) != other[ i ] )
return false;
return true;
}
Jakub Klinkovský
committed
template< typename Index,
typename Device,
typename LocalIndex,
int step >
__cuda_callable__
Jakub Klinkovský
committed
bool
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
operator!=( const EllpackIndexMultimapValues& other ) const
Jakub Klinkovský
committed
{
return ! ( *this == other );
}
Tomáš Oberhuber
committed
template< typename Index,
typename LocalIndex,
int step >
Tomáš Oberhuber
committed
void
EllpackIndexMultimapValues< Index, Device, LocalIndex, step >::
Tomáš Oberhuber
committed
print( std::ostream& str ) const
{
str << "[ ";
if( this->getSize() > 0 )
Tomáš Oberhuber
committed
{
for( typename std::remove_const< Index >::type i = 1; i < this->getSize(); i++ )
str << ", " << this->getValue( i );
Tomáš Oberhuber
committed
}
str << " ]";
}
template< typename Index,
typename LocalIndex,
int step >
std::ostream& operator << ( std::ostream& str, const EllpackIndexMultimapValues< Index, Device, LocalIndex, step >& ports )
Tomáš Oberhuber
committed
{
ports.print( str );
return str;
}
} // namespace Multimaps
} // namespace Containers