241 lines
5.5 KiB
C++
241 lines
5.5 KiB
C++
/******************************************************************************/
|
|
/* ARRAYS - INLINE CODE *******************************************************/
|
|
/******************************************************************************/
|
|
|
|
#ifndef _H_EBCL_INLINE_MULTIARRAYS
|
|
#define _H_EBCL_INLINE_MULTIARRAYS
|
|
#include <ebcl/MultiArrays.hh>
|
|
namespace ebcl {
|
|
|
|
|
|
/*= T_MultiArray ============================================================-*/
|
|
|
|
template< typename T >
|
|
inline void swap( T_MultiArray< T >& lhs , T_MultiArray< T >& rhs )
|
|
{
|
|
using std::swap;
|
|
swap( lhs.meta_ , rhs.meta_ );
|
|
swap( lhs.values_ , rhs.values_ );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::next( )
|
|
{
|
|
const auto sz( meta_.size( ) );
|
|
const auto first( ( sz == 0 ) ? 0 : ( meta_[ sz - 2 ] + meta_[ sz - 1 ] ) );
|
|
meta_ << first << 0;
|
|
}
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::add( T value )
|
|
{
|
|
if ( meta_.size( ) == 0 ) {
|
|
meta_ << 0 << 1;
|
|
} else {
|
|
meta_[ meta_.size( ) - 1 ] ++;
|
|
}
|
|
values_ << value;
|
|
}
|
|
|
|
template< typename T >
|
|
template<
|
|
typename Q ,
|
|
typename... Args ,
|
|
typename >
|
|
inline Q& T_MultiArray< T >::addNew( Args&& ... args )
|
|
{
|
|
if ( meta_.size( ) == 0 ) {
|
|
meta_ << 0 << 1;
|
|
} else {
|
|
meta_[ meta_.size( ) - 1 ] ++;
|
|
}
|
|
return values_.addNew( std::forward< Args >( args ) ... );
|
|
}
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::copyFrom( T_Array< T > const& source )
|
|
{
|
|
values_.addAll( source );
|
|
if ( meta_.size( ) == 0 ) {
|
|
meta_ << 0 << source.size( );
|
|
} else {
|
|
meta_[ meta_.size( ) - 1 ] += source.size( );
|
|
}
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline uint32_t T_MultiArray< T >::size( ) const noexcept
|
|
{
|
|
return meta_.size( ) >> 1;
|
|
}
|
|
|
|
template< typename T >
|
|
inline uint32_t T_MultiArray< T >::firstOf( uint32_t item ) const noexcept
|
|
{
|
|
return meta_[ item * 2 ];
|
|
}
|
|
|
|
template< typename T >
|
|
inline uint32_t T_MultiArray< T >::sizeOf( uint32_t item ) const noexcept
|
|
{
|
|
return meta_[ item * 2 + 1 ];
|
|
}
|
|
|
|
template< typename T >
|
|
inline uint32_t T_MultiArray< T >::values( ) const noexcept
|
|
{
|
|
return values_.size( );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline T const& T_MultiArray< T >::get( uint32_t item , uint32_t sub ) const
|
|
{
|
|
assert( sub < meta_[ item * 2 + 1 ] );
|
|
return values_[ meta_[ item * 2 ] + sub ];
|
|
}
|
|
|
|
template< typename T >
|
|
inline T& T_MultiArray< T >::get( uint32_t item , uint32_t sub )
|
|
{
|
|
assert( sub < meta_[ item * 2 + 1 ] );
|
|
return values_[ meta_[ item * 2 ] + sub ];
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline T const& T_MultiArray< T >::operator[] ( uint32_t index ) const
|
|
{
|
|
return values_[ index ];
|
|
}
|
|
|
|
template< typename T >
|
|
inline T& T_MultiArray< T >::operator[] ( uint32_t index )
|
|
{
|
|
return values_[ index ];
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline bool T_MultiArray< T >::contains( uint32_t index , T const& value ) const
|
|
{
|
|
const auto first( firstOf( index ) );
|
|
const auto end( first + sizeOf( index ) );
|
|
for ( uint32_t i = first ; i < end ; i ++ ) {
|
|
if ( values_[ i ] == value ) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::clear( )
|
|
{
|
|
meta_.clear( );
|
|
values_.clear( );
|
|
}
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::free( )
|
|
{
|
|
meta_.free( );
|
|
values_.free( );
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::copyFrom( uint32_t index )
|
|
{
|
|
copyFrom( *this , index );
|
|
}
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::copyFrom(
|
|
T_MultiArray< T > const& other , uint32_t index )
|
|
{
|
|
const auto size( other.sizeOf( index ) );
|
|
if ( size == 0 ) {
|
|
return;
|
|
}
|
|
|
|
const auto first( other.firstOf( index ) );
|
|
T const* ptr( &( other[ first ] ) );
|
|
for ( uint32_t i = 0 ; i < size ; i ++ , ptr ++ ) {
|
|
values_ << *ptr;
|
|
}
|
|
if ( meta_.size( ) == 0 ) {
|
|
meta_ << 0 << size;
|
|
} else {
|
|
meta_[ meta_.size( ) - 1 ] += size;
|
|
}
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::copyUnique( uint32_t index )
|
|
{
|
|
copyUnique( *this , index );
|
|
}
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::copyUnique( T_MultiArray< T > const& other , uint32_t index )
|
|
{
|
|
const auto oSize( other.sizeOf( index ) );
|
|
if ( oSize == 0 ) {
|
|
return;
|
|
}
|
|
|
|
const auto ms( meta_.size( ) );
|
|
const auto tSize( ms == 0 ? 0 : meta_[ ms - 1 ] );
|
|
const auto tFirst( ms == 0 ? 0 : meta_[ ms - 2 ] );
|
|
|
|
const auto oFirst( other.firstOf( index ) );
|
|
T const* ptr( &( other[ oFirst ] ) );
|
|
|
|
uint32_t added = 0;
|
|
for ( uint32_t i = 0 ; i < oSize ; i ++ , ptr ++ ) {
|
|
bool found = false;
|
|
if ( tSize != 0 ) {
|
|
T const* pCheck( &values_[ tFirst ] );
|
|
for ( uint32_t j = 0 ; j < tSize ; j ++ , pCheck ++ ) {
|
|
if ( *pCheck == *ptr ) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ( !found ) {
|
|
values_ << *ptr;
|
|
added ++;
|
|
}
|
|
}
|
|
if ( ms == 0 ) {
|
|
meta_ << 0 << added;
|
|
} else {
|
|
meta_[ ms - 1 ] += added;
|
|
}
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
template< typename T >
|
|
inline void T_MultiArray< T >::sort( uint32_t index , F_Comparator< T > cmp )
|
|
{
|
|
values_.sort( meta_[ index * 2 ] , meta_[ index * 2 + 1 ] , cmp );
|
|
}
|
|
|
|
|
|
} // namespace
|
|
#endif // _H_EBCL_INLINE_MULTIARRAYS
|