/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
-#include "order-stats.h"
-#include <libpspp/assertion.h>
-#include <data/val-type.h>
-#include <gl/xalloc.h>
-#include <data/variable.h>
-#include <data/casereader.h>
+
+#include "math/order-stats.h"
+
#include <string.h>
+#include "data/casereader.h"
+#include "data/val-type.h"
+#include "data/variable.h"
+#include "libpspp/assertion.h"
+
+#include "gl/xalloc.h"
+
#if 0
#include <stdio.h>
void
-order_stats_accumulate (struct order_stats **os, size_t nos,
- struct casereader *reader,
- const struct variable *wv,
- const struct variable *var,
- enum mv_class exclude)
+order_stats_accumulate_idx (struct order_stats **os, size_t nos,
+ struct casereader *reader,
+ int wt_idx,
+ int val_idx)
{
struct ccase *cx;
struct ccase *prev_cx = NULL;
for (; (cx = casereader_read (reader)) != NULL; case_unref (cx))
{
- const double weight = wv ? case_data (cx, wv)->f : 1.0;
- const double this_value = case_data (cx, var)->f;
+ const double weight = (wt_idx == -1) ? 1.0 : case_data_idx (cx, wt_idx)->f;
+ const double this_value = case_data_idx (cx, val_idx)->f;
/* The casereader MUST be sorted */
assert (this_value >= prev_value);
- if ( var_is_value_missing (var, case_data (cx, var), exclude))
- continue;
-
- case_unref (prev_cx);
-
if ( prev_value == -DBL_MAX || prev_value == this_value)
c_i += weight;
c_i = weight;
}
+ case_unref (prev_cx);
cc_i += weight;
prev_value = this_value;
prev_cx = case_ref (cx);
}
+void
+order_stats_accumulate (struct order_stats **os, size_t nos,
+ struct casereader *reader,
+ const struct variable *wv,
+ const struct variable *var,
+ enum mv_class exclude)
+{
+ /* Filter out missing cases */
+ reader = casereader_create_filter_missing (reader, &var, 1,
+ exclude, NULL, NULL);
+
+ order_stats_accumulate_idx (os, nos,
+ reader,
+ wv ? var_get_case_index (wv) : -1,
+ var_get_case_index (var));
+}