1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2011, 2012, 2013, 2019 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef MEANS_H
18 #define MEANS_H
19
20 #include "libpspp/hmap.h"
21 #include "libpspp/bt.h"
22 #include "libpspp/compiler.h"
23
24 struct cell_container
25 {
26 /* A hash table containing the cells. The table is indexed by a hash
27 based on the cell's categorical value. */
28 struct hmap map;
29
30 /* A binary tree containing the cells. This is
31 used to sort the elements in order of their categorical
32 values. */
33 struct bt bt;
34 };
35
36
37
38 struct layer
39 {
40 size_t n_factor_vars;
41 const struct variable **factor_vars;
42 };
43
44
45 struct statistic;
46
47 typedef struct statistic *stat_create (struct pool *pool);
48 typedef void stat_update (struct statistic *stat, double w, double x);
49 typedef double stat_get (const struct statistic *);
50 typedef void stat_destroy (struct statistic *);
51
52
53 struct cell_spec
54 {
55 /* Printable title for output */
56 const char *title;
57
58 /* Keyword for syntax */
59 const char *keyword;
60
61 /* The result class for the datum. */
62 const char *rc;
63
64 stat_create *sc;
65 stat_update *su;
66 stat_get *sd;
67 stat_destroy *sf;
68 };
69
70 struct summary
71 {
72 double n_total;
73 double n_missing;
74 };
75
76 /* Intermediate data per table. */
77 struct workspace
78 {
79 /* An array of n_layers integers which are used
80 to permute access into the factor_vars of each layer. */
81 int *control_idx;
82
83 /* An array of n_layers cell_containers which hold the union
84 of instances used respectively by each layer. */
85 struct cell_container *instances;
86
87 struct cell *root_cell;
88 };
89
90 /* The thing parsed after TABLES= */
91 struct mtable
92 {
93 size_t n_dep_vars;
94 const struct variable **dep_vars;
95
96 struct layer **layers;
97 int n_layers;
98
99 int n_combinations;
100
101 /* An array of n_combinations workspaces. */
102 struct workspace *ws;
103
104 /* An array of n_combinations * n_dep_vars summaries.
105 These are displayed in the Case Processing
106 Summary box. */
107 struct summary *summ;
108 };
109
110 /* A structure created by the parser. Contains the definition of the
111 what the procedure should calculate. */
112 struct means
113 {
114 const struct dictionary *dict;
destroy_workspace(const struct mtable * mt,struct workspace * ws)115
116 /* The "tables" (ie, a definition of how the data should
117 be broken down). */
118 struct mtable *table;
119 size_t n_tables;
120
121 /* Missing value class for categorical variables. */
122 enum mv_class ctrl_exclude;
123
124 /* Missing value class for dependent variables */
125 enum mv_class dep_exclude;
126
127 /* The statistics to be calculated for each cell. */
128 int *statistics;
129 int n_statistics;
130
131 /* Pool on which cell functions may allocate data. */
132 struct pool *pool;
133 };
134
135
136
destroy_cell(const struct means * means,const struct mtable * mt,struct cell * cell)137 #define n_MEANS_STATISTICS 17
138 extern const struct cell_spec cell_spec[n_MEANS_STATISTICS];
139
140 /* This enum must be consistent with the array cell_spec (in means-calc.c).
141 A bitfield instead of enums would in my opinion be
142 more elegent. However we want the order of the specified
143 statistics to be retained in the output. */
144 enum
145 {
146 MEANS_MEAN = 0,
147 MEANS_N,
148 MEANS_STDDEV
149 };
150
151
152
153 struct dataset;
154 struct casereader;
155 void run_means (struct means *cmd, struct casereader *input, const struct dataset *ds UNUSED);
156
157 struct lexer;
158 bool means_parse (struct lexer *lexer, struct means *means);
159
160
161
162 #endif
163