sn-tex: Fix indentation (remove tabs).
[sort-networks.git] / src / sn_stage.c
index 1a7b2f9..3e9b728 100644 (file)
@@ -202,7 +202,7 @@ int sn_stage_comparator_check_conflict (sn_stage_t *s, const sn_comparator_t *c0
   return (0);
 } /* int sn_stage_comparator_check_conflict */
 
-int sn_stage_show (sn_stage_t *s)
+int sn_stage_show_fh (sn_stage_t *s, FILE *fh) /* {{{ */
 {
   int lines[s->comparators_num];
   int right[s->comparators_num];
@@ -234,7 +234,7 @@ int sn_stage_show (sn_stage_t *s)
 
   for (i = 0; i < lines_used; i++)
   {
-    printf ("%3i: ", s->depth);
+    fprintf (fh, "%3i: ", s->depth);
 
     for (j = 0; j <= right[i]; j++)
     {
@@ -264,31 +264,36 @@ int sn_stage_show (sn_stage_t *s)
       if (on_elem == 0)
       {
        if (line_after == 0)
-         printf ("     ");
+         fprintf (fh, "     ");
        else
-         printf ("-----");
+         fprintf (fh, "-----");
       }
       else if (on_elem == -1)
       {
        if (line_after == 0)
-         printf ("-!   ");
+         fprintf (fh, "-!   ");
        else
-         printf (" !---");
+         fprintf (fh, " !---");
       }
       else
       {
        if (line_after == 0)
-         printf ("->   ");
+         fprintf (fh, "->   ");
        else
-         printf (" <---");
+         fprintf (fh, " <---");
       }
     } /* for (columns) */
 
-    printf ("\n");
+    fprintf (fh, "\n");
   } /* for (lines) */
 
   return (0);
-} /* int sn_stage_show */
+} /* }}} int sn_stage_show_fh */
+
+int sn_stage_show (sn_stage_t *s) /* {{{ */
+{
+  return (sn_stage_show_fh (s, stdout));
+} /* }}} int sn_stage_show */
 
 int sn_stage_invert (sn_stage_t *s)
 {
@@ -626,6 +631,33 @@ sn_stage_t *sn_stage_unserialize (char **ret_buffer, size_t *ret_buffer_size)
   return (s);
 } /* sn_stage_t *sn_stage_unserialize */
 
+int sn_stage_compare (const sn_stage_t *s0, const sn_stage_t *s1) /* {{{ */
+{
+  int status;
+  int i;
+
+  if (s0 == s1)
+    return (0);
+  else if (s0 == NULL)
+    return (-1);
+  else if (s1 == NULL)
+    return (1);
+
+  if (s0->comparators_num < s1->comparators_num)
+    return (-1);
+  else if (s0->comparators_num > s1->comparators_num)
+    return (1);
+
+  for (i = 0; i < s0->comparators_num; i++)
+  {
+    status = sn_comparator_compare (s0->comparators + i, s1->comparators + i);
+    if (status != 0)
+      return (status);
+  }
+
+  return (0);
+} /* }}} int sn_stage_compare */
+
 uint64_t sn_stage_get_hashval (const sn_stage_t *s) /* {{{ */
 {
   uint64_t hash;