X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Finteraction.c;h=ee5b2bf034e1c407d386b4792baaaeb9ad01cd0f;hb=32ea29485bdd610b7d05dd806c5f06f68da0f0fe;hp=746cc17fa1bcd72acaf0359a7824f1c214705c49;hpb=56f06878e2a9a111f8415ce4ad839b3fe68b85ec;p=pspp diff --git a/src/math/interaction.c b/src/math/interaction.c index 746cc17fa1..ee5b2bf034 100644 --- a/src/math/interaction.c +++ b/src/math/interaction.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2012 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 @@ -34,15 +34,14 @@ Interaction is commutative. That means, that from a mathematical point of view, the order of the variables is irrelevant. However, for display - purposes, and for matching with an interaction's value the order is + purposes, and for matching with an interaction's value the order is pertinent. - - Therefore, when using these functions, make sure the orders of variables + + Therefore, when using these functions, make sure the orders of variables and values match when appropriate. */ - struct interaction * interaction_create (const struct variable *v) { @@ -57,6 +56,24 @@ interaction_create (const struct variable *v) return i; } +/* Deep copy an interaction */ +struct interaction * +interaction_clone (const struct interaction *iact) +{ + int v; + struct interaction *i = xmalloc (sizeof *i); + i->vars = xcalloc (iact->n_vars, sizeof *i->vars); + i->n_vars = iact->n_vars; + + for (v = 0; v < iact->n_vars; ++v) + { + i->vars[v] = iact->vars[v]; + } + + return i; +} + + void interaction_destroy (struct interaction *i) { @@ -89,7 +106,7 @@ interaction_is_proper_subset (const struct interaction *x, const struct interact } /* - Do the variables in X->VARS constitute a + Do the variables in X->VARS constitute a subset (proper or otherwise) of the variables in Y->VARS? */ bool @@ -115,7 +132,7 @@ interaction_is_subset (const struct interaction *x, const struct interaction *y) } } - /* If ALL the members of X were also found in Y, then this must be a subset */ + /* If ALL the members of X were also found in Y, then this must be a subset */ if (n >= x->n_vars) return true; @@ -129,11 +146,14 @@ void interaction_dump (const struct interaction *i) { int v = 0; - printf ("%s", var_get_name (i->vars[v])); - for (v = 1; v < i->n_vars; ++v) + if ( i->n_vars == 0) { - printf (" * %s", var_get_name (i->vars[v])); + printf ("(empty)\n"); + return; } + printf ("%s", var_get_name (i->vars[v])); + for (v = 1; v < i->n_vars; ++v) + printf (" * %s", var_get_name (i->vars[v])); printf ("\n"); } @@ -146,6 +166,8 @@ void interaction_to_string (const struct interaction *iact, struct string *str) { int v = 0; + if ( iact->n_vars == 0) + return; ds_put_cstr (str, var_to_string (iact->vars[v])); for (v = 1; v < iact->n_vars; ++v) { @@ -155,10 +177,10 @@ interaction_to_string (const struct interaction *iact, struct string *str) } unsigned int -interaction_case_hash (const struct interaction *iact, const struct ccase *c) +interaction_case_hash (const struct interaction *iact, const struct ccase *c, unsigned int base) { int i; - size_t hash = 0; + size_t hash = base; for (i = 0; i < iact->n_vars; ++i) { const struct variable *var = iact->vars[i];