Line data Source code
1 : /* File: data_stat.inl; Copyright and License: see below */
2 :
3 : #include "utf8stringbuf/utf8stringbuf.h"
4 : #include "u8/u8_trace.h"
5 : #include <assert.h>
6 :
7 193 : static inline void data_stat_init ( data_stat_t *this_ )
8 : {
9 : assert( (int)DATA_TABLE_CLASSIFIER < (int)DATA_STAT_TABLE_MAX );
10 : assert( (int)DATA_TABLE_FEATURE < (int)DATA_STAT_TABLE_MAX );
11 : assert( (int)DATA_TABLE_RELATIONSHIP < (int)DATA_STAT_TABLE_MAX );
12 : assert( (int)DATA_TABLE_DIAGRAMELEMENT < (int)DATA_STAT_TABLE_MAX );
13 : assert( (int)DATA_TABLE_DIAGRAM < (int)DATA_STAT_TABLE_MAX );
14 :
15 1351 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
16 : {
17 8106 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
18 : {
19 6948 : (*this_).data[tables_idx][series_idx] = 0;
20 : }
21 : }
22 193 : }
23 :
24 5 : static inline void data_stat_reinit ( data_stat_t *this_ )
25 : {
26 5 : data_stat_destroy( this_ );
27 5 : data_stat_init( this_ );
28 5 : }
29 :
30 193 : static inline void data_stat_destroy ( data_stat_t *this_ )
31 : {
32 193 : }
33 :
34 256 : static inline uint_fast32_t data_stat_get_count ( const data_stat_t *this_,
35 : data_stat_table_t table,
36 : data_stat_series_t series )
37 : {
38 256 : assert( table < DATA_STAT_TABLE_MAX );
39 256 : assert( series < DATA_STAT_SERIES_MAX );
40 256 : return (*this_).data[table][series];
41 : }
42 :
43 272 : static inline void data_stat_inc_count ( data_stat_t *this_,
44 : data_stat_table_t table,
45 : data_stat_series_t series )
46 : {
47 272 : assert( table < DATA_STAT_TABLE_MAX );
48 272 : assert( series < DATA_STAT_SERIES_MAX );
49 272 : (*this_).data[table][series]++;
50 272 : }
51 :
52 41 : static inline void data_stat_add_count ( data_stat_t *this_,
53 : data_stat_table_t table,
54 : data_stat_series_t series,
55 : int_fast32_t increment )
56 : {
57 41 : assert( table < DATA_STAT_TABLE_MAX );
58 41 : assert( series < DATA_STAT_SERIES_MAX );
59 41 : (*this_).data[table][series] += increment;
60 41 : }
61 :
62 1 : static inline void data_stat_add ( data_stat_t *this_, const data_stat_t *that )
63 : {
64 1 : assert( that != NULL );
65 7 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
66 : {
67 42 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
68 : {
69 36 : (*this_).data[tables_idx][series_idx] += (*that).data[tables_idx][series_idx];
70 : }
71 : }
72 1 : }
73 :
74 2 : static inline uint_fast32_t data_stat_get_series_count ( const data_stat_t *this_,
75 : data_stat_series_t series )
76 : {
77 2 : assert( series < DATA_STAT_SERIES_MAX );
78 2 : uint_fast32_t result = 0;
79 14 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
80 : {
81 12 : result += (*this_).data[tables_idx][series];
82 : }
83 2 : return result;
84 : }
85 :
86 17 : static inline uint_fast32_t data_stat_get_table_count ( const data_stat_t *this_,
87 : data_stat_table_t table )
88 : {
89 17 : assert( table < DATA_STAT_TABLE_MAX );
90 17 : uint_fast32_t result = 0;
91 119 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
92 : {
93 102 : result += (*this_).data[table][series_idx];
94 : }
95 17 : return result;
96 : }
97 :
98 186 : static inline uint_fast32_t data_stat_get_total_count ( const data_stat_t *this_ )
99 : {
100 186 : uint_fast32_t result = 0;
101 1302 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
102 : {
103 7812 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
104 : {
105 6696 : result += (*this_).data[tables_idx][series_idx];
106 : }
107 : }
108 186 : return result;
109 : }
110 :
111 1 : static void inline data_stat_reset_series( data_stat_t *this_, data_stat_series_t series )
112 : {
113 1 : assert( series < DATA_STAT_SERIES_MAX );
114 7 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
115 : {
116 6 : (*this_).data[tables_idx][series] = 0;
117 : }
118 1 : }
119 :
120 :
121 : /*
122 : Copyright 2020-2026 Andreas Warnke
123 :
124 : Licensed under the Apache License, Version 2.0 (the "License");
125 : you may not use this file except in compliance with the License.
126 : You may obtain a copy of the License at
127 :
128 : http://www.apache.org/licenses/LICENSE-2.0
129 :
130 : Unless required by applicable law or agreed to in writing, software
131 : distributed under the License is distributed on an "AS IS" BASIS,
132 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133 : See the License for the specific language governing permissions and
134 : limitations under the License.
135 : */
|