From: Florian Forster Date: Tue, 21 Dec 2010 08:33:52 +0000 (+0100) Subject: Rename "sn-batcher" to "sn-bitonicsort". X-Git-Tag: v1.0.0~6 X-Git-Url: https://git.octo.it/?p=sort-networks.git;a=commitdiff_plain;h=d602a8356687728b0973eeb6d4b6da881238f89c Rename "sn-batcher" to "sn-bitonicsort". --- diff --git a/README b/README index 11eb0e3..61e90d1 100644 --- a/README +++ b/README @@ -19,10 +19,9 @@ The distribution includes the following utility programs: Reads a list of values from STDIN and applies a given comparator network to the list. The resulting list of printed to STDOUT. - * sn-batcher - Creates a batcher bitonic-merge-sort network with a given number of inputs - and prints the network to STDOUT. The number of inputs must be a power of - two. + * sn-bitonicsort + Creates a bitonic mergesort network with a given number of inputs and + prints the network to STDOUT. The number of inputs must be a power of two. * sn-check-bf Does a brute-force check whether a given comparator network is a sort diff --git a/src/Makefile.am b/src/Makefile.am index e30ca07..aa0f298 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ include_HEADERS = sn_network.h sn_stage.h sn_comparator.h lib_LTLIBRARIES = libsortnetwork.la -bin_PROGRAMS = sn-apply sn-batcher sn-bb sn-bb-merge sn-check-bf sn-cut \ +bin_PROGRAMS = sn-apply sn-bitonicsort sn-bb sn-bb-merge sn-check-bf sn-cut \ sn-info sn-markov sn-merge sn-normalize \ sn-oddevenmerge sn-oddevensort sn-pairwise \ sn-shmoo sn-show sn-svg sn-tex @@ -16,9 +16,6 @@ libsortnetwork_la_LDFLAGS = -version-info 0:0:0 sn_apply_SOURCES = sn-apply.c sn_apply_LDADD = libsortnetwork.la -sn_batcher_SOURCES = sn-batcher.c -sn_batcher_LDADD = libsortnetwork.la - sn_bb_SOURCES = sn-bb.c sn_bb_LDADD = libsortnetwork.la -lm @@ -26,6 +23,9 @@ sn_bb_merge_SOURCES = sn-bb.c sn_bb_merge_CPPFLAGS = $(AM_CPPFLAGS) -DBUILD_MERGE=1 sn_bb_merge_LDADD = libsortnetwork.la -lm +sn_bitonicsort_SOURCES = sn-bitonicsort.c +sn_bitonicsort_LDADD = libsortnetwork.la + sn_check_bf_SOURCES = sn-check-bf.c sn_check_bf_LDADD = libsortnetwork.la diff --git a/src/sn-batcher.c b/src/sn-batcher.c deleted file mode 100644 index 13f6d8e..0000000 --- a/src/sn-batcher.c +++ /dev/null @@ -1,123 +0,0 @@ -/** - * libsortnetwork - src/sn-batcher.c - * 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 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. - * - * 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 - * - * Authors: - * Florian octo Forster - **/ - -#ifndef _ISOC99_SOURCE -# define _ISOC99_SOURCE -#endif -#ifndef _POSIX_C_SOURCE -# define _POSIX_C_SOURCE 200112L -#endif - -#include -#include - -#include "sn_network.h" - -static sn_network_t *create_batcher_sort (size_t inputs_num) -{ - sn_network_t *n; - sn_network_t *n_small; - - if (inputs_num == 2) - { - sn_stage_t *s; - sn_comparator_t c; - - n = sn_network_create (2); - if (n == NULL) - { - fprintf (stderr, "create_batcher_sort: sn_network_create failed.\n"); - return (NULL); - } - - s = sn_stage_create (0); - if (s == NULL) - { - sn_network_destroy (n); - fprintf (stderr, "create_batcher_sort: sn_stage_create failed.\n"); - return (NULL); - } - - c.min = 0; - c.max = 1; - - sn_stage_comparator_add (s, &c); - sn_network_stage_add (n, s); - - return (n); - } - else if ((inputs_num < 2) || ((inputs_num % 2) != 0)) - { - fprintf (stderr, "create_batcher_sort: Inputs must be a power of two, " - "sorry.\n"); - return (NULL); - } - - n_small = create_batcher_sort (inputs_num / 2); - if (n_small == NULL) - return (NULL); - - n = sn_network_combine_bitonic_merge (n_small, n_small); - if (n == NULL) - { - sn_network_destroy (n_small); - fprintf (stderr, "create_batcher_sort: sn_network_combine_bitonic_merge " - "failed.\n"); - return (NULL); - } - - sn_network_destroy (n_small); - sn_network_compress (n); - - return (n); -} /* sn_network_t *create_batcher_sort */ - -int main (int argc, char **argv) -{ - sn_network_t *n; - size_t inputs_num; - - if (argc != 2) - { - printf ("Usage: %s \n", argv[0]); - return (0); - } - - inputs_num = (size_t) atoi (argv[1]); - if (inputs_num < 2) - { - fprintf (stderr, "Invalid number of inputs: %zu\n", inputs_num); - return (1); - } - - n = create_batcher_sort (inputs_num); - if (n == NULL) - { - printf ("n == NULL!\n"); - return (1); - } - - sn_network_write (n, stdout); - - return (0); -} /* int main */ - -/* vim: set shiftwidth=2 softtabstop=2 : */ diff --git a/src/sn-bitonicsort.c b/src/sn-bitonicsort.c new file mode 100644 index 0000000..9a69dc2 --- /dev/null +++ b/src/sn-bitonicsort.c @@ -0,0 +1,123 @@ +/** + * libsortnetwork - src/sn-bitonicsort.c + * 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 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. + * + * 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 + * + * Authors: + * Florian octo Forster + **/ + +#ifndef _ISOC99_SOURCE +# define _ISOC99_SOURCE +#endif +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif + +#include +#include + +#include "sn_network.h" + +static sn_network_t *create_batcher_sort (size_t inputs_num) +{ + sn_network_t *n; + sn_network_t *n_small; + + if (inputs_num == 2) + { + sn_stage_t *s; + sn_comparator_t c; + + n = sn_network_create (2); + if (n == NULL) + { + fprintf (stderr, "create_batcher_sort: sn_network_create failed.\n"); + return (NULL); + } + + s = sn_stage_create (0); + if (s == NULL) + { + sn_network_destroy (n); + fprintf (stderr, "create_batcher_sort: sn_stage_create failed.\n"); + return (NULL); + } + + c.min = 0; + c.max = 1; + + sn_stage_comparator_add (s, &c); + sn_network_stage_add (n, s); + + return (n); + } + else if ((inputs_num < 2) || ((inputs_num % 2) != 0)) + { + fprintf (stderr, "create_batcher_sort: Inputs must be a power of two, " + "sorry.\n"); + return (NULL); + } + + n_small = create_batcher_sort (inputs_num / 2); + if (n_small == NULL) + return (NULL); + + n = sn_network_combine_bitonic_merge (n_small, n_small); + if (n == NULL) + { + sn_network_destroy (n_small); + fprintf (stderr, "create_batcher_sort: sn_network_combine_bitonic_merge " + "failed.\n"); + return (NULL); + } + + sn_network_destroy (n_small); + sn_network_compress (n); + + return (n); +} /* sn_network_t *create_batcher_sort */ + +int main (int argc, char **argv) +{ + sn_network_t *n; + size_t inputs_num; + + if (argc != 2) + { + printf ("Usage: %s \n", argv[0]); + return (0); + } + + inputs_num = (size_t) atoi (argv[1]); + if (inputs_num < 2) + { + fprintf (stderr, "Invalid number of inputs: %zu\n", inputs_num); + return (1); + } + + n = create_batcher_sort (inputs_num); + if (n == NULL) + { + printf ("n == NULL!\n"); + return (1); + } + + sn_network_write (n, stdout); + + return (0); +} /* int main */ + +/* vim: set shiftwidth=2 softtabstop=2 : */