LCOV - code coverage report
Current view: top level - data/include/set - data_small_set.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 87 103 84.5 %
Date: 2024-04-07 11:14:42 Functions: 13 14 92.9 %

          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         252 : static inline void data_small_set_init ( data_small_set_t *this_ )
       8             : {
       9         252 :     (*this_).count = 0;
      10         252 : }
      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          37 : static inline void data_small_set_destroy ( data_small_set_t *this_ )
      18             : {
      19          37 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      20             : 
      21          59 :     for ( uint32_t index = 0; index < (*this_).count; index ++ )
      22             :     {
      23          22 :         data_id_destroy( &((*this_).id_set[index]) );
      24             :     }
      25          37 :     (*this_).count = 0;
      26          37 : }
      27             : 
      28          22 : static inline void data_small_set_trace ( const data_small_set_t *this_ )
      29             : {
      30          22 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      31             : 
      32          22 :     U8_TRACE_INFO( "data_small_set_t" );
      33          22 :     U8_TRACE_INFO_INT( "- count:", (*this_).count );
      34          43 :     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          22 : }
      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_id_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         212 : static inline u8_error_t data_small_set_add_obj ( data_small_set_t *this_, data_id_t obj_id )
      96             : {
      97         212 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
      98             :     u8_error_t result;
      99         212 :     result = U8_ERROR_NONE;
     100             : 
     101         212 :     if ( data_id_is_valid( &obj_id ) )
     102             :     {
     103        8643 :         for ( uint32_t index = 0; index < (*this_).count; index ++ )
     104             :         {
     105        8433 :             if ( data_id_equals( &obj_id, &((*this_).id_set[index]) ) )
     106             :             {
     107           1 :                 result = U8_ERROR_DUPLICATE_ID;
     108             :             }
     109             :         }
     110         210 :         if ( result == U8_ERROR_NONE )
     111             :         {
     112         209 :             if ( (*this_).count < DATA_SMALL_SET_MAX_SET_SIZE )
     113             :             {
     114         207 :                 (*this_).id_set[(*this_).count] = obj_id;
     115         207 :                 (*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         212 :     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_id_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          22 : static inline void data_small_set_clear ( data_small_set_t *this_ )
     180             : {
     181          22 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
     182             : 
     183          23 :     for ( uint32_t index = 0; index < (*this_).count; index ++ )
     184             :     {
     185           1 :         data_id_destroy( &((*this_).id_set[index]) );
     186             :     }
     187          22 :     (*this_).count = 0;
     188          22 : }
     189             : 
     190         289 : static inline uint32_t data_small_set_get_count ( const data_small_set_t *this_ )
     191             : {
     192         289 :     return (*this_).count;
     193             : }
     194             : 
     195          76 : static inline data_id_t data_small_set_get_id ( const data_small_set_t *this_, uint32_t index )
     196             : {
     197          76 :     assert( (*this_).count <= DATA_SMALL_SET_MAX_SET_SIZE );
     198             :     data_id_t result;
     199             : 
     200          76 :     if ( index < (*this_).count )
     201             :     {
     202          76 :         result = (*this_).id_set[index];
     203             :     }
     204             :     else
     205             :     {
     206           0 :         data_id_init_void( &result );
     207             :     }
     208             : 
     209          76 :     return result;
     210             : }
     211             : 
     212             : /*
     213             : Copyright 2016-2024 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 1.16