LCOV - code coverage report
Current view: top level - data/include/set - data_small_set.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 84.5 % 103 87
Test Date: 2025-05-01 10:10:14 Functions: 92.9 % 14 13

            Line data    Source code
       1              : /* File: data_small_set.inl; Copyright and License: see below */
       2              : 
       3              : #include "u8/u8_trace.h"
       4              : #include "u8/u8_log.h"
       5              : #include <assert.h>
       6              : 
       7          285 : static inline void data_small_set_init ( data_small_set_t *this_ )
       8              : {
       9          285 :     (*this_).count = 0;
      10          285 : }
      11              : 
      12            0 : static inline void data_small_set_reinit ( data_small_set_t *this_ )
      13              : {
      14            0 :     data_small_set_clear( this_ );
      15            0 : }
      16              : 
      17          100 : static inline void data_small_set_destroy ( data_small_set_t *this_ )
      18              : {
      19          100 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      20              : 
      21          162 :     for ( uint32_t index = 0; index < (*this_).count; index ++ )
      22              :     {
      23           62 :         data_id_destroy( &((*this_).id_set[index]) );
      24              :     }
      25          100 :     (*this_).count = 0;
      26          100 : }
      27              : 
      28           25 : static inline void data_small_set_trace ( const data_small_set_t *this_ )
      29              : {
      30           25 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      31              : 
      32           25 :     U8_TRACE_INFO( "data_small_set_t" );
      33           25 :     U8_TRACE_INFO_INT( "- count:", (*this_).count );
      34           46 :     for ( uint32_t index = 0; index < (*this_).count; index ++ )
      35              :     {
      36           21 :         switch ( data_id_get_table( &((*this_).id_set[index]) ))
      37              :         {
      38            0 :             case DATA_TABLE_VOID:
      39            0 :                 U8_TRACE_INFO_INT("- []: table = DATA_TABLE_VOID, row_id =", data_id_get_row_id( &((*this_).id_set[index]) ) );
      40            0 :                 break;
      41            2 :             case DATA_TABLE_CLASSIFIER:
      42            2 :                 U8_TRACE_INFO_INT("- []: table = DATA_TABLE_CLASSIFIER, row_id =", data_id_get_row_id( &((*this_).id_set[index]) ) );
      43            2 :                 break;
      44            0 :             case DATA_TABLE_FEATURE:
      45            0 :                 U8_TRACE_INFO_INT("- []: table = DATA_TABLE_FEATURE, row_id =", data_id_get_row_id( &((*this_).id_set[index]) ) );
      46            0 :                 break;
      47            2 :             case DATA_TABLE_RELATIONSHIP:
      48            2 :                 U8_TRACE_INFO_INT("- []: table = DATA_TABLE_RELATIONSHIP, row_id =", data_id_get_row_id( &((*this_).id_set[index]) ) );
      49            2 :                 break;
      50            0 :             case DATA_TABLE_DIAGRAMELEMENT:
      51            0 :                 U8_TRACE_INFO_INT("- []: table = DATA_TABLE_DIAGRAMELEMENT, row_id =", data_id_get_row_id( &((*this_).id_set[index]) ) );
      52            0 :                 break;
      53           17 :             case DATA_TABLE_DIAGRAM:
      54           17 :                 U8_TRACE_INFO_INT("- []: table = DATA_TABLE_DIAGRAM, row_id =", data_id_get_row_id( &((*this_).id_set[index]) ) );
      55           17 :                 break;
      56            0 :             default:
      57            0 :                 U8_LOG_ERROR("- []: illegal value");
      58            0 :                 break;
      59              :         }
      60              :     }
      61           25 : }
      62              : 
      63            9 : static inline bool data_small_set_is_empty ( const data_small_set_t *this_ )
      64              : {
      65            9 :     return ( 0 == (*this_).count );
      66              : }
      67              : 
      68          274 : static inline bool data_small_set_contains ( const data_small_set_t *this_, data_id_t obj_id )
      69              : {
      70          274 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      71              :     bool result;
      72          274 :     result = false;
      73              : 
      74        17057 :     for ( uint32_t index = 0; ( index < (*this_).count ) && ( false == result ); index ++ )
      75              :     {
      76        16783 :         if ( data_id_equals( &obj_id, &((*this_).id_set[index]) ) )
      77              :         {
      78          134 :             result = true;
      79              :         }
      80              :     }
      81              : 
      82          274 :     return result;
      83              : }
      84              : 
      85            2 : static inline bool data_small_set_contains_row_id ( const data_small_set_t *this_, data_table_t table, data_row_t row_id )
      86              : {
      87              :     bool result;
      88              :     data_id_t my_id;
      89            2 :     data_id_init( &my_id, table, row_id );
      90            2 :     result = data_small_set_contains( this_, my_id );
      91            2 :     data_id_destroy( &my_id );
      92            2 :     return result;
      93              : }
      94              : 
      95          244 : static inline u8_error_t data_small_set_add_obj ( data_small_set_t *this_, data_id_t obj_id )
      96              : {
      97          244 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      98              :     u8_error_t result;
      99          244 :     result = U8_ERROR_NONE;
     100              : 
     101          244 :     if ( data_id_is_valid( &obj_id ) )
     102              :     {
     103         8677 :         for ( uint32_t index = 0; index < (*this_).count; index ++ )
     104              :         {
     105         8435 :             if ( data_id_equals( &obj_id, &((*this_).id_set[index]) ) )
     106              :             {
     107            1 :                 result = U8_ERROR_DUPLICATE_ID;
     108              :             }
     109              :         }
     110          242 :         if ( result == U8_ERROR_NONE )
     111              :         {
     112          241 :             if ( (*this_).count < DATA_SMALL_SET_MAX_SET_SIZE )
     113              :             {
     114          239 :                 (*this_).id_set[(*this_).count] = obj_id;
     115          239 :                 (*this_).count ++;
     116              :             }
     117              :             else
     118              :             {
     119            2 :                 result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
     120              :             }
     121              :         }
     122              :     }
     123              :     else
     124              :     {
     125            2 :         result = U8_ERROR_INVALID_REQUEST;
     126              :     }
     127              : 
     128          244 :     return result;
     129              : }
     130              : 
     131           48 : static inline u8_error_t data_small_set_add_row_id ( data_small_set_t *this_, data_table_t table, data_row_t row_id )
     132              : {
     133              :     bool result;
     134              :     data_id_t my_id;
     135           48 :     data_id_init( &my_id, table, row_id );
     136           48 :     result = data_small_set_add_obj( this_, my_id );
     137           48 :     data_id_destroy( &my_id );
     138           48 :     return result;
     139              : }
     140              : 
     141          132 : static inline u8_error_t data_small_set_delete_obj ( data_small_set_t *this_, data_id_t obj_id )
     142              : {
     143          132 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
     144              :     u8_error_t result;
     145          132 :     result = U8_ERROR_INVALID_REQUEST;
     146              : 
     147         8328 :     for ( uint32_t index = 0; index < (*this_).count; index ++ )
     148              :     {
     149         8196 :         if ( data_id_equals( &obj_id, &((*this_).id_set[index]) ) )
     150              :         {
     151          131 :             result = U8_ERROR_NONE;
     152          131 :             data_id_destroy( &((*this_).id_set[index]) );
     153              : 
     154          131 :             (*this_).count --;
     155          131 :             (*this_).id_set[index] = (*this_).id_set[(*this_).count];
     156              :         }
     157              :     }
     158              : 
     159          132 :     return result;
     160              : }
     161              : 
     162            4 : static inline u8_error_t data_small_set_toggle_obj ( data_small_set_t *this_, data_id_t obj_id )
     163              : {
     164              :     u8_error_t result;
     165              : 
     166            4 :     if ( data_small_set_contains( this_, obj_id ) )
     167              :     {
     168            1 :         result = data_small_set_delete_obj( this_, obj_id );
     169            1 :         assert( result == U8_ERROR_NONE );
     170              :     }
     171              :     else
     172              :     {
     173            3 :         result = data_small_set_add_obj( this_, obj_id );
     174              :     }
     175              : 
     176            4 :     return result;
     177              : }
     178              : 
     179           25 : static inline void data_small_set_clear ( data_small_set_t *this_ )
     180              : {
     181           25 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
     182              : 
     183           26 :     for ( uint32_t index = 0; index < (*this_).count; index ++ )
     184              :     {
     185            1 :         data_id_destroy( &((*this_).id_set[index]) );
     186              :     }
     187           25 :     (*this_).count = 0;
     188           25 : }
     189              : 
     190          322 : static inline uint32_t data_small_set_get_count ( const data_small_set_t *this_ )
     191              : {
     192          322 :     return (*this_).count;
     193              : }
     194              : 
     195           79 : static inline data_id_t data_small_set_get_id ( const data_small_set_t *this_, uint32_t index )
     196              : {
     197           79 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
     198              :     data_id_t result;
     199              : 
     200           79 :     if ( index < (*this_).count )
     201              :     {
     202           79 :         result = (*this_).id_set[index];
     203              :     }
     204              :     else
     205              :     {
     206            0 :         data_id_init_void( &result );
     207              :     }
     208              : 
     209           79 :     return result;
     210              : }
     211              : 
     212              : /*
     213              : Copyright 2016-2025 Andreas Warnke
     214              : 
     215              : Licensed under the Apache License, Version 2.0 (the "License");
     216              : you may not use this file except in compliance with the License.
     217              : You may obtain a copy of the License at
     218              : 
     219              :     http://www.apache.org/licenses/LICENSE-2.0
     220              : 
     221              : Unless required by applicable law or agreed to in writing, software
     222              : distributed under the License is distributed on an "AS IS" BASIS,
     223              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     224              : See the License for the specific language governing permissions and
     225              : limitations under the License.
     226              : */
        

Generated by: LCOV version 2.0-1