From e980194778b2e1effc06b2b967f1b3634de8abaf Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 25 Apr 2008 11:05:03 +0200 Subject: [PATCH] sn_stage.[ch]: Add the sn_stage_clone method. --- src/sn_stage.c | 23 +++++++++++++++++++++++ src/sn_stage.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/sn_stage.c b/src/sn_stage.c index f0d169d..85ec45d 100644 --- a/src/sn_stage.c +++ b/src/sn_stage.c @@ -89,6 +89,29 @@ int sn_stage_comparator_remove (sn_stage_t *s, int c_num) return (0); } /* int sn_stage_comparator_remove */ +sn_stage_t *sn_stage_clone (const sn_stage_t *s) +{ + sn_stage_t *s_copy; + + s_copy = sn_stage_create (s->depth); + if (s_copy == NULL) + return (NULL); + + s_copy->comparators = (sn_comparator_t *) malloc (s->comparators_num + * sizeof (sn_comparator_t)); + if (s_copy->comparators == NULL) + { + free (s_copy); + return (NULL); + } + + memcpy (s_copy->comparators, s->comparators, + s->comparators_num * sizeof (sn_comparator_t)); + s_copy->comparators_num = s->comparators_num; + + return (s_copy); +} /* sn_stage_t *sn_stage_clone */ + int sn_stage_comparator_check_conflict (sn_stage_t *s, const sn_comparator_t *c0) { int i; diff --git a/src/sn_stage.h b/src/sn_stage.h index 465a4c2..514c4ad 100644 --- a/src/sn_stage.h +++ b/src/sn_stage.h @@ -24,6 +24,7 @@ enum sn_network_cut_dir_e #define SN_STAGE_COMP_GET(s,n) ((s)->comparators + (n)) sn_stage_t *sn_stage_create (int depth); +sn_stage_t *sn_stage_clone (const sn_stage_t *s); void sn_stage_destroy (sn_stage_t *s); int sn_stage_comparator_add (sn_stage_t *s, const sn_comparator_t *c); -- 2.11.0