2 * libsortnetwork - src/sn_network.c
3 * Copyright (C) 2008-2010 Florian octo Forster
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or (at
8 * your option) any later version.
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Florian octo Forster <ff at octo.it>
23 #ifndef _ISOC99_SOURCE
24 # define _ISOC99_SOURCE
26 #ifndef _POSIX_C_SOURCE
27 # define _POSIX_C_SOURCE 200112L
31 # define DPRINTF(...) fprintf (stderr, "sn_network: " __VA_ARGS__)
33 # define DPRINTF(...) /**/
44 #include "sn_network.h"
45 #include "sn_random.h"
47 sn_network_t *sn_network_create (int inputs_num) /* {{{ */
51 n = (sn_network_t *) malloc (sizeof (sn_network_t));
54 memset (n, '\0', sizeof (sn_network_t));
56 n->inputs_num = inputs_num;
59 } /* }}} sn_network_t *sn_network_create */
61 void sn_network_destroy (sn_network_t *n) /* {{{ */
66 if (n->stages != NULL)
69 for (i = 0; i < n->stages_num; i++)
71 sn_stage_destroy (n->stages[i]);
79 } /* }}} void sn_network_destroy */
81 sn_network_t *sn_network_create_odd_even_mergesort (int inputs_num) /* {{{ */
85 assert (inputs_num > 0);
88 return (sn_network_create (inputs_num));
94 n = sn_network_create (inputs_num);
96 memset (&c, 0, sizeof (c));
100 sn_network_comparator_add (n, &c);
106 sn_network_t *n_left;
107 sn_network_t *n_right;
111 inputs_left = inputs_num / 2;
112 inputs_right = inputs_num - inputs_left;
114 n_left = sn_network_create_odd_even_mergesort (inputs_left);
118 n_right = sn_network_create_odd_even_mergesort (inputs_right);
121 sn_network_destroy (n_left);
125 n = sn_network_combine_odd_even_merge (n_left, n_right);
127 sn_network_destroy (n_left);
128 sn_network_destroy (n_right);
131 sn_network_compress (n);
135 } /* }}} sn_network_t *sn_network_create_odd_even_mergesort */
137 sn_network_t *sn_network_create_bitonic_mergesort (int inputs_num) /* {{{ */
141 assert (inputs_num > 0);
144 return (sn_network_create (inputs_num));
150 n = sn_network_create (inputs_num);
152 memset (&c, 0, sizeof (c));
156 sn_network_comparator_add (n, &c);
162 sn_network_t *n_left;
163 sn_network_t *n_right;
167 inputs_left = inputs_num / 2;
168 inputs_right = inputs_num - inputs_left;
170 n_left = sn_network_create_bitonic_mergesort (inputs_left);
174 if (inputs_left != inputs_right)
175 n_right = sn_network_create_bitonic_mergesort (inputs_right);
180 sn_network_destroy (n_left);
184 n = sn_network_combine_bitonic_merge (n_left, n_right);
186 if (n_left != n_right)
187 sn_network_destroy (n_right);
188 sn_network_destroy (n_left);
191 sn_network_compress (n);
195 } /* }}} sn_network_t *sn_network_create_bitonic_mergesort */
197 static int sn_network_create_pairwise_internal (sn_network_t *n, /* {{{ */
198 int *inputs, int inputs_num)
201 int inputs_copy[inputs_num];
204 for (i = 1; i < inputs_num; i += 2)
206 sn_comparator_t *c = sn_comparator_create (inputs[i-1], inputs[i]);
207 sn_network_comparator_add (n, c);
208 sn_comparator_destroy (c);
214 /* Sort "pairs" recursively. Like with odd-even mergesort, odd and even lines
215 * are handled recursively and later reunited. */
216 for (i = 0; i < inputs_num; i += 2)
217 inputs_copy[(int) (i / 2)] = inputs[i];
218 /* Recursive call #1 with first set of lines */
219 sn_network_create_pairwise_internal (n, inputs_copy,
220 (int) ((inputs_num + 1) / 2));
222 for (i = 1; i < inputs_num; i += 2)
223 inputs_copy[(int) (i / 2)] = inputs[i];
224 /* Recursive call #2 with second set of lines */
225 sn_network_create_pairwise_internal (n, inputs_copy,
226 (int) (inputs_num/ 2));
228 /* m is the "amplitude" of the sorted pairs. This is a bit tricky to read due
229 * to different indices being used in the paper, unfortunately. */
233 for (i = 1; (i + (m - 1)) < inputs_num; i += 2)
236 int right = i + (m - 1);
239 assert (left < right);
240 c = sn_comparator_create (inputs[left], inputs[right]);
241 sn_network_comparator_add (n, c);
242 sn_comparator_destroy (c);
246 } /* while (m > 1) */
249 } /* }}} int sn_network_create_pairwise_internal */
251 sn_network_t *sn_network_create_pairwise (int inputs_num) /* {{{ */
253 sn_network_t *n = sn_network_create (inputs_num);
254 int inputs[inputs_num];
260 for (i = 0; i < inputs_num; i++)
263 sn_network_create_pairwise_internal (n, inputs, inputs_num);
264 sn_network_compress (n);
267 } /* }}} sn_network_t *sn_network_create_pairwise */
269 int sn_network_network_add (sn_network_t *n, sn_network_t *other) /* {{{ */
274 if ((n == NULL) || (other == NULL))
277 stages_num = n->stages_num + other->stages_num;
278 if (stages_num <= n->stages_num)
281 tmp = realloc (n->stages, sizeof (*n->stages) * stages_num);
286 memcpy (n->stages + n->stages_num, other->stages,
287 sizeof (*other->stages) * other->stages_num);
288 n->stages_num = stages_num;
290 free (other->stages);
294 } /* }}} int sn_network_network_add */
296 int sn_network_stage_add (sn_network_t *n, sn_stage_t *s) /* {{{ */
300 if ((n == NULL) || (s == NULL))
303 temp = (sn_stage_t **) realloc (n->stages, (n->stages_num + 1)
304 * sizeof (sn_stage_t *));
309 SN_STAGE_DEPTH (s) = n->stages_num;
310 n->stages[n->stages_num] = s;
314 } /* }}} int sn_network_stage_add */
316 int sn_network_stage_remove (sn_network_t *n, int s_num) /* {{{ */
318 int nmemb = n->stages_num - (s_num + 1);
321 if ((n == NULL) || (s_num >= n->stages_num))
324 sn_stage_destroy (n->stages[s_num]);
325 n->stages[s_num] = NULL;
329 memmove (n->stages + s_num, n->stages + (s_num + 1),
330 nmemb * sizeof (sn_stage_t *));
331 n->stages[n->stages_num - 1] = NULL;
335 /* Free the unused memory */
336 if (n->stages_num == 0)
343 temp = (sn_stage_t **) realloc (n->stages,
344 n->stages_num * sizeof (sn_stage_t *));
351 } /* }}} int sn_network_stage_remove */
353 sn_network_t *sn_network_clone (const sn_network_t *n) /* {{{ */
355 sn_network_t *n_copy;
358 n_copy = sn_network_create (n->inputs_num);
362 for (i = 0; i < n->stages_num; i++)
367 s = sn_stage_clone (n->stages[i]);
371 status = sn_network_stage_add (n_copy, s);
376 if (i < n->stages_num)
378 sn_network_destroy (n_copy);
383 } /* }}} sn_network_t *sn_network_clone */
385 int sn_network_comparator_add (sn_network_t *n, /* {{{ */
386 const sn_comparator_t *c)
390 if ((n == NULL) || (c == NULL))
393 if (n->stages_num > 0)
395 s = n->stages[n->stages_num - 1];
397 if (sn_stage_comparator_check_conflict (s, c) == 0)
399 sn_stage_comparator_add (s, c);
404 s = sn_stage_create (n->stages_num);
405 sn_stage_comparator_add (s, c);
406 sn_network_stage_add (n, s);
409 } /* }}} int sn_network_comparator_add */
411 int sn_network_get_comparator_num (const sn_network_t *n) /* {{{ */
420 for (i = 0; i < n->stages_num; i++)
421 num += n->stages[i]->comparators_num;
424 } /* }}} int sn_network_get_comparator_num */
426 int sn_network_show (sn_network_t *n) /* {{{ */
430 for (i = 0; i < n->stages_num; i++)
431 sn_stage_show (n->stages[i]);
434 } /* }}} int sn_network_show */
436 int sn_network_invert (sn_network_t *n) /* {{{ */
443 for (i = 0; i < n->stages_num; i++)
444 sn_stage_invert (n->stages[i]);
447 } /* }}} int sn_network_invert */
449 int sn_network_shift (sn_network_t *n, int sw) /* {{{ */
453 if ((n == NULL) || (sw < 0))
459 for (i = 0; i < n->stages_num; i++)
460 sn_stage_shift (n->stages[i], sw, SN_NETWORK_INPUT_NUM (n));
463 } /* }}} int sn_network_shift */
465 int sn_network_compress (sn_network_t *n) /* {{{ */
471 for (i = 1; i < n->stages_num; i++)
477 for (j = 0; j < SN_STAGE_COMP_NUM (s); j++)
479 sn_comparator_t *c = SN_STAGE_COMP_GET (s, j);
482 for (k = i - 1; k >= 0; k--)
486 conflict = sn_stage_comparator_check_conflict (n->stages[k], c);
501 sn_stage_comparator_add (n->stages[move_to], c);
502 sn_stage_comparator_remove (s, j);
508 while ((n->stages_num > 0)
509 && (SN_STAGE_COMP_NUM (n->stages[n->stages_num - 1]) == 0))
510 sn_network_stage_remove (n, n->stages_num - 1);
513 } /* }}} int sn_network_compress */
515 int sn_network_normalize (sn_network_t *n) /* {{{ */
519 for (i = 0; i < n->stages_num; i++)
526 for (j = 0; j < SN_STAGE_COMP_NUM (s); j++)
532 c = SN_STAGE_COMP_GET (s, j);
541 for (k = i; k < n->stages_num; k++)
542 sn_stage_swap (n->stages[k], min, max);
547 } /* for (j = 0 .. #comparators) */
548 } /* for (i = n->stages_num - 1 .. 0) */
551 } /* }}} int sn_network_normalize */
553 int sn_network_unify (sn_network_t *n) /* {{{ */
560 sn_network_normalize (n);
561 sn_network_compress (n);
563 for (i = 0; i < n->stages_num; i++)
564 sn_stage_unify (n->stages[i]);
567 } /* }}} int sn_network_unify */
569 int sn_network_remove_input (sn_network_t *n, int input) /* {{{ */
573 if ((n == NULL) || (input < 0) || (input >= n->inputs_num))
576 for (i = 0; i < n->stages_num; i++)
577 sn_stage_remove_input (n->stages[i], input);
582 } /* }}} int sn_network_remove_input */
584 int sn_network_cut_at (sn_network_t *n, int input, /* {{{ */
585 enum sn_network_cut_dir_e dir)
588 int position = input;
590 for (i = 0; i < n->stages_num; i++)
596 new_position = sn_stage_cut_at (s, position, dir);
598 if (position != new_position)
602 for (j = 0; j < i; j++)
603 sn_stage_swap (n->stages[j], position, new_position);
606 position = new_position;
609 assert (((dir == DIR_MIN) && (position == 0))
610 || ((dir == DIR_MAX) && (position == (n->inputs_num - 1))));
612 sn_network_remove_input (n, position);
615 } /* }}} int sn_network_cut_at */
617 int sn_network_cut (sn_network_t *n, int *mask) /* {{{ */
622 for (i = 0; i < n->stages_num; i++)
624 sn_stage_t *s = n->stages[i];
626 sn_stage_cut (s, mask, n->stages);
629 /* Use a copy of this member since it will be updated by
630 * sn_network_remove_input(). */
631 inputs_num = n->inputs_num;
632 for (i = 0; i < inputs_num; i++)
635 sn_network_remove_input (n, 0);
636 else if (mask[i] > 0)
637 sn_network_remove_input (n, n->inputs_num - 1);
641 } /* }}} int sn_network_cut */
643 /* sn_network_concatenate
645 * `Glues' two networks together, resulting in a comparator network with twice
646 * as many inputs but one that doesn't really sort anymore. It produces a
647 * bitonic sequence, though, that can be used by the mergers below. */
648 static sn_network_t *sn_network_concatenate (sn_network_t *n0, /* {{{ */
656 stages_num = (n0->stages_num > n1->stages_num)
660 n = sn_network_create (n0->inputs_num + n1->inputs_num);
664 for (i = 0; i < stages_num; i++)
666 sn_stage_t *s = sn_stage_create (i);
668 if (i < n0->stages_num)
669 for (j = 0; j < SN_STAGE_COMP_NUM (n0->stages[i]); j++)
671 sn_comparator_t *c = SN_STAGE_COMP_GET (n0->stages[i], j);
672 sn_stage_comparator_add (s, c);
675 if (i < n1->stages_num)
676 for (j = 0; j < SN_STAGE_COMP_NUM (n1->stages[i]); j++)
678 sn_comparator_t *c_orig = SN_STAGE_COMP_GET (n1->stages[i], j);
679 sn_comparator_t c_copy;
681 SN_COMP_MIN(&c_copy) = SN_COMP_MIN(c_orig) + n0->inputs_num;
682 SN_COMP_MAX(&c_copy) = SN_COMP_MAX(c_orig) + n0->inputs_num;
684 sn_stage_comparator_add (s, &c_copy);
687 sn_network_stage_add (n, s);
691 } /* }}} sn_network_t *sn_network_concatenate */
693 static int sn_network_add_bitonic_merger (sn_network_t *n, /* {{{ */
694 int *indizes, int indizes_num)
698 if (indizes_num <= 1)
703 int even_indizes[indizes_num];
704 int even_indizes_num;
705 int odd_indizes[indizes_num];
708 even_indizes_num = (indizes_num + 1) / 2;
709 odd_indizes_num = indizes_num / 2;
711 for (i = 0; i < even_indizes_num; i++)
712 even_indizes[i] = indizes[2 * i];
713 for (i = 0; i < odd_indizes_num; i++)
714 odd_indizes[i] = indizes[(2 * i) + 1];
716 sn_network_add_bitonic_merger (n, even_indizes, even_indizes_num);
717 sn_network_add_bitonic_merger (n, odd_indizes, odd_indizes_num);
720 for (i = 1; i < indizes_num; i += 2)
724 memset (&c, 0, sizeof (c));
725 c.min = indizes[i - 1];
728 sn_network_comparator_add (n, &c);
732 } /* }}} int sn_network_add_bitonic_merger */
734 static int sn_network_add_odd_even_merger (sn_network_t *n, /* {{{ */
735 int *indizes_left, int indizes_left_num,
736 int *indizes_right, int indizes_right_num)
738 int tmp_left[indizes_left_num];
740 int tmp_right[indizes_left_num];
746 if ((indizes_left_num == 0) || (indizes_right_num == 0))
750 else if ((indizes_left_num == 1) && (indizes_right_num == 1))
755 c.min = *indizes_left;
756 c.max = *indizes_right;
758 s = sn_stage_create (n->stages_num);
762 sn_stage_comparator_add (s, &c);
763 sn_network_stage_add (n, s);
768 /* Merge odd sequences */
769 tmp_left_num = (indizes_left_num + 1) / 2;
770 for (i = 0; i < tmp_left_num; i++)
771 tmp_left[i] = indizes_left[2 * i];
773 tmp_right_num = (indizes_right_num + 1) / 2;
774 for (i = 0; i < tmp_right_num; i++)
775 tmp_right[i] = indizes_right[2 * i];
777 sn_network_add_odd_even_merger (n,
778 tmp_left, tmp_left_num,
779 tmp_right, tmp_right_num);
781 /* Merge even sequences */
782 tmp_left_num = indizes_left_num / 2;
783 for (i = 0; i < tmp_left_num; i++)
784 tmp_left[i] = indizes_left[(2 * i) + 1];
786 tmp_right_num = indizes_right_num / 2;
787 for (i = 0; i < tmp_right_num; i++)
788 tmp_right[i] = indizes_right[(2 * i) + 1];
790 sn_network_add_odd_even_merger (n,
791 tmp_left, tmp_left_num,
792 tmp_right, tmp_right_num);
794 /* Apply ``comparison-interchange'' operations. */
795 s = sn_stage_create (n->stages_num);
797 max_index = indizes_left_num + indizes_right_num;
798 if ((max_index % 2) == 0)
803 for (i = 1; i <= max_index; i += 2)
807 if (i < indizes_left_num)
808 c.min = indizes_left[i];
810 c.min = indizes_right[i - indizes_left_num];
812 if ((i + 1) < indizes_left_num)
813 c.max = indizes_left[i + 1];
815 c.max = indizes_right[i + 1 - indizes_left_num];
817 sn_stage_comparator_add (s, &c);
820 sn_network_stage_add (n, s);
823 } /* }}} int sn_network_add_odd_even_merger */
825 sn_network_t *sn_network_combine_bitonic_merge (sn_network_t *n0, /* {{{ */
828 sn_network_t *n0_clone;
830 int indizes_num = SN_NETWORK_INPUT_NUM (n0) + SN_NETWORK_INPUT_NUM (n1);
831 int indizes[indizes_num];
834 /* We need to invert n0, because the sequence must be
835 * z_1 >= z_2 >= ... >= z_k <= z_{k+1} <= ... <= z_p
836 * and NOT the other way around! Otherwise the comparators added in
837 * sn_network_add_bitonic_merger() from comparing (z_0,z_1), (z_2,z_3), ...
838 * to comparing ..., (z_{n-4},z_{n-3}), (z_{n-2},z_{n-1}), i.e. bound to the
839 * end of the list, possibly leaving z_0 uncompared. */
840 n0_clone = sn_network_clone (n0);
841 if (n0_clone == NULL)
843 sn_network_invert (n0_clone);
845 n = sn_network_concatenate (n0_clone, n1);
848 sn_network_destroy (n0_clone);
850 for (i = 0; i < indizes_num; i++)
853 sn_network_add_bitonic_merger (n, indizes, indizes_num);
856 } /* }}} sn_network_t *sn_network_combine_bitonic_merge */
858 sn_network_t *sn_network_combine_odd_even_merge (sn_network_t *n0, /* {{{ */
862 int indizes_left[n0->inputs_num];
863 int indizes_left_num;
864 int indizes_right[n1->inputs_num];
865 int indizes_right_num;
869 indizes_left_num = n0->inputs_num;
870 indizes_right_num = n1->inputs_num;
871 for (i = 0; i < indizes_left_num; i++)
873 for (i = 0; i < indizes_right_num; i++)
874 indizes_right[i] = indizes_left_num + i;
876 n = sn_network_concatenate (n0, n1);
880 status = sn_network_add_odd_even_merger (n,
881 indizes_left, indizes_left_num,
882 indizes_right, indizes_right_num);
885 sn_network_destroy (n);
889 sn_network_compress (n);
891 } /* }}} sn_network_t *sn_network_combine_odd_even_merge */
893 sn_network_t *sn_network_combine (sn_network_t *n0, /* {{{ */
896 return (sn_network_combine_odd_even_merge (n0, n1));
897 } /* }}} sn_network_t *sn_network_combine */
899 int sn_network_sort (sn_network_t *n, int *values) /* {{{ */
905 for (i = 0; i < n->stages_num; i++)
907 status = sn_stage_sort (n->stages[i], values);
913 } /* }}} int sn_network_sort */
915 int sn_network_brute_force_check (sn_network_t *n) /* {{{ */
917 int test_pattern[n->inputs_num];
918 int values[n->inputs_num];
922 memset (test_pattern, 0, sizeof (test_pattern));
928 /* Copy the current pattern and let the network sort it */
929 memcpy (values, test_pattern, sizeof (values));
930 status = sn_network_sort (n, values);
934 /* Check if the array is now sorted. */
935 previous = values[0];
936 for (i = 1; i < n->inputs_num; i++)
938 if (previous > values[i])
940 previous = values[i];
943 /* Generate the next test pattern */
945 for (i = 0; i < n->inputs_num; i++)
947 if (test_pattern[i] == 0)
960 /* Break out of the while loop if we tested all possible patterns */
965 /* All tests successfull */
967 } /* }}} int sn_network_brute_force_check */
969 sn_network_t *sn_network_read (FILE *fh) /* {{{ */
976 while (fgets (buffer, sizeof (buffer), fh) != NULL)
978 char *str_key = buffer;
979 char *str_value = NULL;
980 int buffer_len = strlen (buffer);
982 while ((buffer_len > 0) && ((buffer[buffer_len - 1] == '\n')
983 || (buffer[buffer_len - 1] == '\r')))
986 buffer[buffer_len] = '\0';
991 str_value = strchr (buffer, ':');
992 if (str_value == NULL)
994 printf ("Cannot parse line: %s\n", buffer);
998 *str_value = '\0'; str_value++;
999 while ((*str_value != '\0') && (isspace (*str_value) != 0))
1002 if (strcasecmp ("Inputs", str_key) == 0)
1003 opt_inputs = atoi (str_value);
1005 printf ("Unknown key: %s\n", str_key);
1006 } /* while (fgets) */
1011 n = sn_network_create (opt_inputs);
1017 s = sn_stage_read (fh);
1021 sn_network_stage_add (n, s);
1024 if (SN_NETWORK_STAGE_NUM (n) < 1)
1026 sn_network_destroy (n);
1031 } /* }}} sn_network_t *sn_network_read */
1033 sn_network_t *sn_network_read_file (const char *file) /* {{{ */
1038 fh = fopen (file, "r");
1042 n = sn_network_read (fh);
1047 } /* }}} sn_network_t *sn_network_read_file */
1049 int sn_network_write (sn_network_t *n, FILE *fh) /* {{{ */
1053 fprintf (fh, "Inputs: %i\n", n->inputs_num);
1056 for (i = 0; i < n->stages_num; i++)
1057 sn_stage_write (n->stages[i], fh);
1060 } /* }}} int sn_network_write */
1062 int sn_network_write_file (sn_network_t *n, const char *file) /* {{{ */
1067 fh = fopen (file, "w");
1071 status = sn_network_write (n, fh);
1076 } /* }}} int sn_network_write_file */
1078 int sn_network_serialize (sn_network_t *n, char **ret_buffer, /* {{{ */
1079 size_t *ret_buffer_size)
1086 buffer = *ret_buffer;
1087 buffer_size = *ret_buffer_size;
1089 #define SNPRINTF_OR_FAIL(...) \
1090 status = snprintf (buffer, buffer_size, __VA_ARGS__); \
1091 if ((status < 1) || (((size_t) status) >= buffer_size)) \
1094 buffer_size -= status;
1096 SNPRINTF_OR_FAIL ("Inputs: %i\r\n\r\n", n->inputs_num);
1098 for (i = 0; i < n->stages_num; i++)
1100 status = sn_stage_serialize (n->stages[i], &buffer, &buffer_size);
1105 *ret_buffer = buffer;
1106 *ret_buffer_size = buffer_size;
1108 } /* }}} int sn_network_serialize */
1110 sn_network_t *sn_network_unserialize (char *buffer, /* {{{ */
1116 if (buffer_size == 0)
1119 /* Read options first */
1120 while (buffer_size > 0)
1129 endptr = strchr (buffer, '\n');
1136 line_len = strlen (line);
1138 if ((line_len > 0) && (line[line_len - 1] == '\r'))
1140 line[line_len - 1] = 0;
1148 str_value = strchr (line, ':');
1149 if (str_value == NULL)
1151 printf ("Cannot parse line: %s\n", line);
1155 *str_value = '\0'; str_value++;
1156 while ((*str_value != '\0') && (isspace (*str_value) != 0))
1159 if (strcasecmp ("Inputs", str_key) == 0)
1160 opt_inputs = atoi (str_value);
1162 printf ("Unknown key: %s\n", str_key);
1163 } /* while (fgets) */
1168 n = sn_network_create (opt_inputs);
1174 s = sn_stage_unserialize (&buffer, &buffer_size);
1178 sn_network_stage_add (n, s);
1181 if (SN_NETWORK_STAGE_NUM (n) < 1)
1183 sn_network_destroy (n);
1188 } /* }}} sn_network_t *sn_network_unserialize */
1190 uint64_t sn_network_get_hashval (const sn_network_t *n) /* {{{ */
1198 hash = (uint64_t) n->inputs_num;
1200 for (i = 0; i < n->stages_num; i++)
1201 hash = (hash * 104207) + sn_stage_get_hashval (n->stages[i]);
1204 } /* }}} uint64_t sn_network_get_hashval */
1206 /* vim: set sw=2 sts=2 et fdm=marker : */