X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fmath%2Forder-stats.c;h=59edc92fc80fe28af97237893ae89f39d344e1a3;hb=51cf173b5eaaa8c5cc6233f9c8924eb44498e89d;hp=9f54e8730c9bfda7ce738b5311df3016f3c9cdbf;hpb=b8e468c47bf5ef5148b570466cd3225b4c02a3d3;p=pspp
diff --git a/src/math/order-stats.c b/src/math/order-stats.c
index 9f54e8730c..59edc92fc8 100644
--- a/src/math/order-stats.c
+++ b/src/math/order-stats.c
@@ -1,5 +1,5 @@
/* 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
@@ -15,14 +15,18 @@
along with this program. If not, see . */
#include
-#include "order-stats.h"
-#include
-#include
-#include
-#include
-#include
+
+#include "math/order-stats.h"
+
#include
+#include "data/casereader.h"
+#include "data/val-type.h"
+#include "data/variable.h"
+#include "libpspp/assertion.h"
+
+#include "gl/xalloc.h"
+
#if 0
#include
@@ -58,7 +62,7 @@ static void
update_k_lower (struct k *kk,
double y_i, double c_i, double cc_i)
{
- if ( cc_i <= kk->tc )
+ if (cc_i <= kk->tc)
{
kk->cc = cc_i;
kk->c = c_i;
@@ -71,7 +75,7 @@ static void
update_k_upper (struct k *kk,
double y_i, double c_i, double cc_i)
{
- if ( cc_i > kk->tc && kk->c_p1 == 0)
+ if (cc_i > kk->tc && kk->c_p1 == 0)
{
kk->cc_p1 = cc_i;
kk->c_p1 = c_i;
@@ -98,7 +102,7 @@ update_k_values (const struct ccase *cx, double y_i, double c_i, double cc_i,
update_k_upper (myk, y_i, c_i, cc_i);
}
- if ( stat->accumulate )
+ if (stat->accumulate)
stat->accumulate (stat, cx, c_i, cc_i, y_i);
tos->cc = cc_i;
@@ -107,11 +111,10 @@ update_k_values (const struct ccase *cx, double y_i, double c_i, double cc_i,
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;
@@ -122,19 +125,16 @@ order_stats_accumulate (struct order_stats **os, size_t nos,
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;
-
- if ( prev_value == -DBL_MAX || prev_value == this_value)
+ if (prev_value == -DBL_MAX || prev_value == this_value)
c_i += weight;
- if ( prev_value > -DBL_MAX && this_value > prev_value)
+ if (prev_value > -DBL_MAX && this_value > prev_value)
{
update_k_values (prev_cx, prev_value, c_i, cc_i, os, nos);
c_i = weight;
@@ -153,4 +153,20 @@ order_stats_accumulate (struct order_stats **os, size_t nos,
}
+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));
+}