- An interaction is a gsl_vector containing a "product" of other
- variables. The variables can be either categorical or numeric.
- If the variables are all numeric, the interaction is just the
- scalar product. If any of the variables are categorical, their
- product is a vector containing 0's in all but one entry. This entry
- is found by combining the vectors corresponding to the variables'
- OBS_VALS member. If there are K categorical variables, each with
- N_1, N_2, ..., N_K categories, then the interaction will have
- N_1 * N_2 * N_3 *...* N_K - 1 entries.
+ An interaction is a structure containing a "product" of other
+ variables. The variables can be either string or numeric.
+
+ 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
+ pertinent.
+
+ Therefore, when using these functions, make sure the orders of variables
+ and values match when appropriate.
+*/
+
+
+struct interaction *
+interaction_create (const struct variable *v)
+{
+ struct interaction *i = xmalloc (sizeof *i);
+ i->vars = xmalloc (sizeof *i->vars);
+ i->n_vars = 0;
+ if ( v )
+ {
+ i->vars[0] = v;
+ i->n_vars = 1;
+ }
+ 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)
+{
+ if (NULL == i)
+ return;
+
+ free (i->vars);
+ free (i);
+}
+
+void
+interaction_add_variable (struct interaction *i, const struct variable *v)
+{
+ i->vars = xrealloc (i->vars, sizeof (*i->vars) * ++i->n_vars);
+ i->vars[i->n_vars - 1] = v;
+}
+
+
+/*
+ Do the variables in X->VARS constitute a proper
+ subset of the variables in Y->VARS?