#include "language/lexer/lexer.h"
#include "language/lexer/variable-parser.h"
#include "language/stats/freq.h"
+#include "libpspp/array.h"
#include "libpspp/assertion.h"
#include "libpspp/hmap.h"
#include "libpspp/message.h"
{
struct var_array vars;
struct hmap data; /* Contains "struct freq"s. */
+ struct freq **sorted;
};
+static int
+compare_freq_3way (const void *a_, const void *b_, const void *vars_)
+{
+ const struct var_array *vars = vars_;
+ struct freq *const *a = a_;
+ struct freq *const *b = b_;
+
+ for (size_t i = 0; i < vars->n; i++)
+ {
+ int cmp = value_compare_3way (&(*a)->values[i], &(*b)->values[i],
+ var_get_width (vars->vars[i]));
+ if (cmp)
+ return cmp;
+ }
+
+ return 0;
+}
+
static bool
ctables_execute (struct dataset *ds, struct ctables *ct)
{
}
casereader_destroy (input);
+ for (size_t i = 0; i < n_fts; i++)
+ {
+ struct ctables_freqtab *ft = fts[i];
+ ft->sorted = xnmalloc (ft->data.count, sizeof *ft->sorted);
+
+ struct freq *f;
+ size_t n = 0;
+ HMAP_FOR_EACH (f, struct freq, node, &ft->data)
+ ft->sorted[n++] = f;
+ sort (ft->sorted, ft->data.count, sizeof *ft->sorted,
+ compare_freq_3way, &ft->vars);
+ }
+
for (size_t i = 0; i < n_fts; i++)
{
struct ctables_freqtab *ft = fts[i];
free (f);
}
hmap_destroy (&ft->data);
+ free (ft->sorted);
var_array_uninit (&ft->vars);
free (ft);
}