MultiArray - Function that returns total values count

This commit is contained in:
Emmanuel BENOîT 2018-05-07 12:57:26 +02:00
parent d2122aff38
commit 8f939b6a32
3 changed files with 67 additions and 47 deletions

View file

@ -379,11 +379,13 @@ class T_MultiArray
void copyFrom( T_Data const& source );
// Returns the amount of entries
uint32_t size( ) const;
uint32_t size( ) const noexcept;
// Returns the index of the first value for an entry
uint32_t firstOf( uint32_t item ) const;
uint32_t firstOf( uint32_t item ) const noexcept;
// Returns the amount of values for an entry
uint32_t sizeOf( uint32_t item ) const;
uint32_t sizeOf( uint32_t item ) const noexcept;
// Returns the amount of values across all entries
uint32_t values( ) const noexcept;
// Access a value in an entry
T const& get( uint32_t item , uint32_t sub ) const;

View file

@ -1553,23 +1553,29 @@ inline void T_MultiArray< T >::copyFrom( T_Array< T > const& source )
/*----------------------------------------------------------------------------*/
template< typename T >
inline uint32_t T_MultiArray< T >::size( ) const
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
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
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 >

View file

@ -142,6 +142,7 @@ void ArraysMultiTest::testInitialSize( )
{
T_Test empty;
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , empty.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , empty.values( ) );
}
/*----------------------------------------------------------------------------*/
@ -153,6 +154,7 @@ void ArraysMultiTest::testNext( )
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.values( ) );
}
void ArraysMultiTest::testNextMultiple( )
@ -160,11 +162,12 @@ void ArraysMultiTest::testNextMultiple( )
T_Test test;
test.next( );
test.next( );
CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.sizeOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.sizeOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.values( ) );
}
/*----------------------------------------------------------------------------*/
@ -174,9 +177,10 @@ void ArraysMultiTest::testAddToEmpty( )
T_Test test;
test.next( );
test.add( 0 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.values( ) );
}
void ArraysMultiTest::testAdd( )
@ -185,9 +189,10 @@ void ArraysMultiTest::testAdd( )
test.next( );
test.add( 0 );
test.add( 0 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.values( ) );
}
void ArraysMultiTest::testAddNewToEmpty( )
@ -195,9 +200,10 @@ void ArraysMultiTest::testAddNewToEmpty( )
T_ObjTest test;
test.next( );
test.addNew( 1 , 2 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.values( ) );
}
void ArraysMultiTest::testAddNew( )
@ -206,9 +212,10 @@ void ArraysMultiTest::testAddNew( )
test.next( );
test.addNew( 1 , 2 );
test.addNew( 3 , 4 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.values( ) );
}
void ArraysMultiTest::testNextAfterAdd( )
@ -221,13 +228,14 @@ void ArraysMultiTest::testNextAfterAdd( )
test.add( 0 );
test.next( );
test.add( 0 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 3 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , test.sizeOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.firstOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.sizeOf( 2 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 3 ) , test.firstOf( 2 ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.sizeOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.firstOf( 1 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.sizeOf( 2 ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.firstOf( 2 ) );
CPPUNIT_ASSERT_EQUAL( 4u , test.values( ) );
}
/*----------------------------------------------------------------------------*/
@ -241,9 +249,10 @@ void ArraysMultiTest::testCopyFromToEmpty( )
test.next( );
test.copyFrom( values );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 3 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.values( ) );
}
void ArraysMultiTest::testCopyFrom( )
@ -256,9 +265,10 @@ void ArraysMultiTest::testCopyFrom( )
test.add( 0 );
test.copyFrom( values );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 4 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 4u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 4u , test.values( ) );
}
void ArraysMultiTest::testCopyFromEmpty( )
@ -268,9 +278,10 @@ void ArraysMultiTest::testCopyFromEmpty( )
test.next( );
test.copyFrom( values );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.size( ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.sizeOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.firstOf( 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.values( ) );
}
/*----------------------------------------------------------------------------*/
@ -285,10 +296,11 @@ void ArraysMultiTest::testGetRead( )
test.add( 2 );
test.next( );
test.add( 3 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.get( 0 , 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , test.get( 1 , 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , test.get( 1 , 1 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 3 ) , test.get( 2 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.get( 0 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 1u , test.get( 1 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.get( 1 , 1 ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.get( 2 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 4u , test.values( ) );
}
void ArraysMultiTest::testGetWrite( )
@ -302,10 +314,10 @@ void ArraysMultiTest::testGetWrite( )
test.next( );
test.add( 3 );
test.get( 1 , 0 ) = 12;
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , test.get( 0 , 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 12 ) , test.get( 1 , 0 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , test.get( 1 , 1 ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 3 ) , test.get( 2 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 0u , test.get( 0 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 12u , test.get( 1 , 0 ) );
CPPUNIT_ASSERT_EQUAL( 2u , test.get( 1 , 1 ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.get( 2 , 0 ) );
}
void ArraysMultiTest::testDirectRead( )