- const double weight = wv ? case_data (&cx, wv)->f : 1.0;
- const double this_value = case_data (&cx, var)->f;
+ const double weight = weight_idx == -1 ? 1.0 : case_num_idx (cx, weight_idx);
+ if (weight == SYSMIS || weight <= 0)
+ continue;
+
+ const double this_value = case_num_idx (cx, data_idx);
+ if (!isfinite (this_value) || this_value == SYSMIS)
+ continue;
+
+ if (!prev_cx || this_value > prev_value)
+ {
+ if (prev_cx)
+ update_k_values (prev_cx, prev_value, c_i, cc_i, os, n_os);
+ prev_value = this_value;
+ c_i = weight;
+ }
+ else
+ {
+ /* Data values must be sorted. */
+ assert (this_value == prev_value);
+
+ c_i += weight;
+ }