X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fmerge.c;h=5b0704d9c26850518041ad52f6457b23344b1952;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=59536da648d8a66be1955a5f27f4880c503111c3;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp-builds.git diff --git a/src/math/merge.c b/src/math/merge.c index 59536da6..5b0704d9 100644 --- a/src/math/merge.c +++ b/src/math/merge.c @@ -1,61 +1,61 @@ -/* PSPP - computes sample statistics. - Copyright (C) 2007 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 2007, 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 the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ /* FIXME: error checking. */ /* FIXME: merge pattern should be improved, this one causes a performance regression. */ #include -#include +#include "math/merge.h" -#include -#include -#include -#include -#include -#include -#include +#include "data/case.h" +#include "data/casereader.h" +#include "data/casewriter.h" +#include "data/subcase.h" +#include "libpspp/array.h" +#include "libpspp/assertion.h" +#include "libpspp/taint.h" -#include "xalloc.h" +#include "gl/xalloc.h" #define MAX_MERGE_ORDER 7 struct merge_input { struct casereader *reader; - struct ccase c; + struct ccase *c; }; struct merge { - struct case_ordering *ordering; + struct subcase ordering; struct merge_input inputs[MAX_MERGE_ORDER]; size_t input_cnt; + struct caseproto *proto; }; static void do_merge (struct merge *m); struct merge * -merge_create (const struct case_ordering *ordering) +merge_create (const struct subcase *ordering, const struct caseproto *proto) { struct merge *m = xmalloc (sizeof *m); - m->ordering = case_ordering_clone (ordering); + subcase_clone (&m->ordering, ordering); m->input_cnt = 0; + m->proto = caseproto_ref (proto); return m; } @@ -66,9 +66,10 @@ merge_destroy (struct merge *m) { size_t i; - case_ordering_destroy (m->ordering); + subcase_destroy (&m->ordering); for (i = 0; i < m->input_cnt; i++) casereader_destroy (m->inputs[i].reader); + caseproto_unref (m->proto); free (m); } } @@ -97,8 +98,7 @@ merge_make_reader (struct merge *m) } else if (m->input_cnt == 0) { - size_t value_cnt = case_ordering_get_value_cnt (m->ordering); - struct casewriter *writer = mem_writer_create (value_cnt); + struct casewriter *writer = mem_writer_create (m->proto); r = casewriter_make_reader (writer); } else @@ -112,7 +112,8 @@ read_input_case (struct merge *m, size_t idx) { struct merge_input *i = &m->inputs[idx]; - if (casereader_read (i->reader, &i->c)) + i->c = casereader_read (i->reader); + if (i->c) return true; else { @@ -131,7 +132,7 @@ do_merge (struct merge *m) assert (m->input_cnt > 1); - w = tmpfile_writer_create (case_ordering_get_value_cnt (m->ordering)); + w = tmpfile_writer_create (m->proto); for (i = 0; i < m->input_cnt; i++) taint_propagate (casereader_get_taint (m->inputs[i].reader), casewriter_get_taint (w)); @@ -145,11 +146,11 @@ do_merge (struct merge *m) min = 0; for (i = 1; i < m->input_cnt; i++) - if (case_ordering_compare_cases (&m->inputs[i].c, &m->inputs[min].c, - m->ordering) < 0) + if (subcase_compare_3way (&m->ordering, m->inputs[i].c, + &m->ordering, m->inputs[min].c) < 0) min = i; - casewriter_write (w, &m->inputs[min].c); + casewriter_write (w, m->inputs[min].c); read_input_case (m, min); }