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 191 : 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 1337 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
16 : {
17 8022 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
18 : {
19 6876 : (*this_).data[tables_idx][series_idx] = 0;
20 : }
21 : }
22 191 : }
23 :
24 191 : static inline void data_stat_destroy ( data_stat_t *this_ )
25 : {
26 191 : }
27 :
28 235 : static inline uint_fast32_t data_stat_get_count ( const data_stat_t *this_,
29 : data_stat_table_t table,
30 : data_stat_series_t series )
31 : {
32 235 : assert( table < DATA_STAT_TABLE_MAX );
33 235 : assert( series < DATA_STAT_SERIES_MAX );
34 235 : return (*this_).data[table][series];
35 : }
36 :
37 265 : static inline void data_stat_inc_count ( data_stat_t *this_,
38 : data_stat_table_t table,
39 : data_stat_series_t series )
40 : {
41 265 : assert( table < DATA_STAT_TABLE_MAX );
42 265 : assert( series < DATA_STAT_SERIES_MAX );
43 265 : (*this_).data[table][series]++;
44 265 : }
45 :
46 1 : static inline void data_stat_add_count ( data_stat_t *this_,
47 : data_stat_table_t table,
48 : data_stat_series_t series,
49 : int_fast32_t increment )
50 : {
51 1 : assert( table < DATA_STAT_TABLE_MAX );
52 1 : assert( series < DATA_STAT_SERIES_MAX );
53 1 : (*this_).data[table][series] += increment;
54 1 : }
55 :
56 1 : static inline void data_stat_add ( data_stat_t *this_, const data_stat_t *that )
57 : {
58 1 : assert( that != NULL );
59 7 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
60 : {
61 42 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
62 : {
63 36 : (*this_).data[tables_idx][series_idx] += (*that).data[tables_idx][series_idx];
64 : }
65 : }
66 1 : }
67 :
68 2 : static inline uint_fast32_t data_stat_get_series_count ( const data_stat_t *this_,
69 : data_stat_series_t series )
70 : {
71 2 : assert( series < DATA_STAT_SERIES_MAX );
72 2 : uint_fast32_t result = 0;
73 14 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
74 : {
75 12 : result += (*this_).data[tables_idx][series];
76 : }
77 2 : return result;
78 : }
79 :
80 14 : static inline uint_fast32_t data_stat_get_table_count ( const data_stat_t *this_,
81 : data_stat_table_t table )
82 : {
83 14 : assert( table < DATA_STAT_TABLE_MAX );
84 14 : uint_fast32_t result = 0;
85 98 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
86 : {
87 84 : result += (*this_).data[table][series_idx];
88 : }
89 14 : return result;
90 : }
91 :
92 187 : static inline uint_fast32_t data_stat_get_total_count ( const data_stat_t *this_ )
93 : {
94 187 : uint_fast32_t result = 0;
95 1309 : for ( int series_idx = 0; series_idx < DATA_STAT_SERIES_MAX; series_idx ++ )
96 : {
97 7854 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
98 : {
99 6732 : result += (*this_).data[tables_idx][series_idx];
100 : }
101 : }
102 187 : return result;
103 : }
104 :
105 1 : static void inline data_stat_reset_series( data_stat_t *this_, data_stat_series_t series )
106 : {
107 1 : assert( series < DATA_STAT_SERIES_MAX );
108 7 : for ( int tables_idx = 0; tables_idx < DATA_STAT_TABLE_MAX; tables_idx ++ )
109 : {
110 6 : (*this_).data[tables_idx][series] = 0;
111 : }
112 1 : }
113 :
114 :
115 : /*
116 : Copyright 2020-2025 Andreas Warnke
117 :
118 : Licensed under the Apache License, Version 2.0 (the "License");
119 : you may not use this file except in compliance with the License.
120 : You may obtain a copy of the License at
121 :
122 : http://www.apache.org/licenses/LICENSE-2.0
123 :
124 : Unless required by applicable law or agreed to in writing, software
125 : distributed under the License is distributed on an "AS IS" BASIS,
126 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127 : See the License for the specific language governing permissions and
128 : limitations under the License.
129 : */
|