Remove unneeded #includes.
[pspp] / src / language / stats / means.h
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 casereader;
25 struct dataset;
26 struct lexer;
27
28 struct cell_container
29 {
30   /* A hash table containing the cells.  The table is indexed by a hash
31      based on the cell's categorical value.  */
32   struct hmap map;
33
34   /* A binary tree containing the cells.  This  is
35    used to sort the elements in order of their categorical
36    values.  */
37   struct bt bt;
38 };
39
40
41
42 struct layer
43 {
44   size_t n_factor_vars;
45   const struct variable **factor_vars;
46 };
47
48
49 struct statistic;
50
51 typedef struct statistic *stat_create (struct pool *pool);
52 typedef void stat_update  (struct statistic *stat, double w, double x);
53 typedef double stat_get   (const struct statistic *);
54 typedef void stat_destroy (struct statistic *);
55
56
57 struct cell_spec
58 {
59   /* Printable title for output */
60   const char *title;
61
62   /* Keyword for syntax */
63   const char *keyword;
64
65   /* The result class for the datum.  */
66   const char *rc;
67
68   stat_create *sc;
69   stat_update *su;
70   stat_get *sd;
71   stat_destroy *sf;
72 };
73
74 struct summary
75 {
76   double n_total;
77   double n_missing;
78 };
79
80 /* Intermediate data per table.  */
81 struct workspace
82 {
83   /* An array of n_layers integers which are used
84      to permute access into the factor_vars of each layer.  */
85   int *control_idx;
86
87   /* An array of n_layers cell_containers which hold the union
88      of instances used respectively by each layer.  */
89   struct cell_container *instances;
90
91   struct cell *root_cell;
92 };
93
94 /* The thing parsed after TABLES= */
95 struct mtable
96 {
97   size_t n_dep_vars;
98   const struct variable **dep_vars;
99
100   struct layer **layers;
101   int n_layers;
102
103   int n_combinations;
104
105   /* An array of n_combinations workspaces.  */
106   struct workspace *ws;
107
108   /* An array of n_combinations * n_dep_vars summaries.
109      These are displayed in the Case Processing
110      Summary box.  */
111   struct summary *summ;
112 };
113
114 /* A structure created by the parser.  Contains the definition of the
115    what the procedure should calculate.  */
116 struct means
117 {
118   const struct dictionary *dict;
119
120   /* The "tables" (ie, a definition of how the data should
121      be broken down).  */
122   struct mtable *table;
123   size_t n_tables;
124
125   /* Missing value class for categorical variables.  */
126   enum mv_class ctrl_exclude;
127
128   /* Missing value class for dependent variables */
129   enum mv_class dep_exclude;
130
131   /* The statistics to be calculated for each cell.  */
132   int *statistics;
133   int n_statistics;
134   size_t allocated_statistics;
135
136   /* Pool on which cell functions may allocate data.  */
137   struct pool *pool;
138 };
139
140
141
142 #define n_MEANS_STATISTICS 17
143 extern const struct cell_spec cell_spec[n_MEANS_STATISTICS];
144
145 /* This enum must be consistent with the array cell_spec (in means-calc.c).
146    A bitfield instead of enums would in my opinion be
147    more elegent.  However we want the order of the specified
148    statistics to be retained in the output.  */
149 enum
150   {
151     MEANS_MEAN = 0,
152     MEANS_N,
153     MEANS_STDDEV
154   };
155
156 void run_means (struct means *, struct casereader *, const struct dataset *);
157 bool means_parse (struct lexer *, struct means *);
158 void means_set_default_statistics (struct means *);
159
160 #endif