src/sn_{network,stage}.[ch]: Implement sn_network_unify().
authorFlorian Forster <octo@leeloo.octo.it>
Thu, 13 Jan 2011 11:56:30 +0000 (12:56 +0100)
committerFlorian Forster <octo@leeloo.octo.it>
Thu, 13 Jan 2011 11:56:30 +0000 (12:56 +0100)
src/sn_network.c
src/sn_network.h
src/sn_stage.c
src/sn_stage.h

index 2071510..c421995 100644 (file)
@@ -550,6 +550,22 @@ int sn_network_normalize (sn_network_t *n) /* {{{ */
   return (0);
 } /* }}} int sn_network_normalize */
 
+int sn_network_unify (sn_network_t *n) /* {{{ */
+{
+  int i;
+
+  if (n == NULL)
+    return (EINVAL);
+
+  sn_network_normalize (n);
+  sn_network_compress (n);
+
+  for (i = 0; i < n->stages_num; i++)
+    sn_stage_unify (n->stages[i]);
+
+  return (0);
+} /* }}} int sn_network_unify */
+
 int sn_network_remove_input (sn_network_t *n, int input) /* {{{ */
 {
   int i;
index 4626d9d..f29c9b3 100644 (file)
@@ -233,6 +233,8 @@ int sn_network_compress (sn_network_t *n);
  */
 int sn_network_normalize (sn_network_t *n);
 
+int sn_network_unify (sn_network_t *n);
+
 /**
  * Removes an input and all comparators touching that input from the comparator
  * network.
index 1b564cc..dc00b44 100644 (file)
@@ -320,6 +320,24 @@ int sn_stage_shift (sn_stage_t *s, int sw, int inputs_num)
   return (0);
 } /* int sn_stage_shift */
 
+static int sn_stage_unify__qsort_callback (const void *p0, const void *p1) /* {{{ */
+{
+  return (sn_comparator_compare (p0, p1));
+} /* }}} int sn_stage_unify__qsort_callback */
+
+int sn_stage_unify (sn_stage_t *s) /* {{{ */
+{
+  if (s == NULL)
+    return (EINVAL);
+
+  qsort (s->comparators,
+      (size_t) s->comparators_num,
+      sizeof (*s->comparators),
+      sn_stage_unify__qsort_callback);
+
+  return (0);
+} /* }}} int sn_stage_unify */
+
 int sn_stage_swap (sn_stage_t *s, int con0, int con1)
 {
   int i;
index ee51b9f..8cd77cf 100644 (file)
@@ -166,6 +166,8 @@ int sn_stage_invert (sn_stage_t *s);
  */
 int sn_stage_shift (sn_stage_t *s, int sw, int inputs_num);
 
+int sn_stage_unify (sn_stage_t *s);
+
 /**
  * Swaps two lines. This is used by the algorithm used in
  * sn_network_normalize() to transform non-standard sort networks to standard