src/sn_{network,stage}.[ch]: Implement sn_{network,stage}_show_fh.
[sort-networks.git] / src / sn_network.h
index 716c2a3..14a36c5 100644 (file)
@@ -8,18 +8,19 @@
  * libsortnetwork - src/sn_network.h
  * Copyright (C) 2008-2010  Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  * Authors:
  *   Florian octo Forster <ff at octo.it>
@@ -30,6 +31,8 @@
 #define SN_NETWORK_H 1
 
 #include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
 
 #include "sn_comparator.h"
 #include "sn_stage.h"
@@ -86,6 +89,15 @@ void sn_network_destroy (sn_network_t *n);
 sn_network_t *sn_network_create_odd_even_mergesort (int inputs_num);
 
 /**
+ * Creates a new sort network using Batcher's Bitonic-Mergesort algorithm.
+ *
+ * \param inputs_num Number of inputs / outputs of the sorting network.
+ * \return A pointer to the newly allocated sorting network or \c NULL if an
+ *   invalid number of inputs was given or allocation failed.
+ */
+sn_network_t *sn_network_create_bitonic_mergesort (int inputs_num);
+
+/**
  * Creates a new sorting network using the Pairwise sorting algorithm published
  * by Ian Parberry.
  * \param inputs_num Number of inputs / outputs of the sorting network.
@@ -184,6 +196,7 @@ int sn_network_brute_force_check (sn_network_t *n);
  * \return Zero on success, non-zero on failure.
  */
 int sn_network_show (sn_network_t *n);
+int sn_network_show_fh (sn_network_t *n, FILE *fh);
 
 /**
  * Inverts a comparator network by switching the direction of all comparators.
@@ -221,6 +234,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.
@@ -341,6 +356,23 @@ int sn_network_serialize (sn_network_t *n, char **ret_buffer,
  * \see sn_network_serialize
  */
 sn_network_t *sn_network_unserialize (char *buffer, size_t buffer_size);
+
+/**
+ * Compares two networks and returns zero if they are equal. If they are not
+ * equal, a number greater than zero or less than zero is returned in a
+ * consistent matter, so this function can be used to sort networks and detect
+ * duplicates. It is strongly recommended that you call sn_network_unify()
+ * before comparing two networks, because they internal structure does matter
+ * for this function.
+ *
+ * \return Zero if the two networks are equal, non-zero otherwise. Return
+ *   values are consistent so this function can be used to sort networks.
+ * \see sn_network_unify
+ */
+int sn_network_compare (const sn_network_t *n0, const sn_network_t *n1);
+
+uint64_t sn_network_get_hashval (const sn_network_t *n);
+
 #endif /* SN_NETWORK_H */
 
 /* vim: set shiftwidth=2 softtabstop=2 : */