From 75e7e4241ba2424c3803548bcf2da0382faf7349 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 9 Dec 2011 11:24:56 +0100 Subject: [PATCH] Added a function to clone an interaction. --- src/math/interaction.c | 19 ++++++++++++++++++- src/math/interaction.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/math/interaction.c b/src/math/interaction.c index 269aa7e9..4e4134f0 100644 --- a/src/math/interaction.c +++ b/src/math/interaction.c @@ -42,7 +42,6 @@ */ - 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) { diff --git a/src/math/interaction.h b/src/math/interaction.h index ccd6706f..23bd4f21 100644 --- a/src/math/interaction.h +++ b/src/math/interaction.h @@ -33,6 +33,7 @@ struct interaction }; struct interaction * interaction_create (const struct variable *); +struct interaction * interaction_clone (const struct interaction *); void interaction_destroy (struct interaction *); void interaction_add_variable (struct interaction *, const struct variable *); void interaction_dump (const struct interaction *); -- 2.30.2