From 14653cd6318fc792fe336e79853b5a2d24b5f591 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 10 May 2008 09:44:30 +0200 Subject: [PATCH] sn-check-bf: Added a brute-force checker. It's a lot faster than the Perl version. \o/ --- src/Makefile | 9 ++++-- src/sn-check-bf.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/sn-check-bf.c diff --git a/src/Makefile b/src/Makefile index 785e30e..4d351f7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,11 +2,14 @@ CC = gcc CFLAGS = -Wall -Werror -std=c99 -O3 -pthread #CFLAGS = -Wall -Werror -std=c99 -O0 -g -pthread -all: sn-apply sn-cut sn-evolution sn-merge sn-normalize sn-show sn-tex +APPLICATIONS = sn-apply sn-check-bf sn-cut sn-evolution sn-merge \ + sn-normalize sn-show sn-tex + +all: $(APPLICATIONS) clean: rm -f *.o - rm -f sn-apply sn-cut sn-evolution sn-merge sn-normalize sn-show sn-tex + rm -f $(APPLICATIONS) sn_comparator.o: sn_comparator.c sn_comparator.h @@ -21,6 +24,8 @@ sn_stage.o: sn_stage.c sn_stage.h sn_comparator.h sn-apply: sn-apply.c sn_network.o sn_stage.o sn_comparator.o sn_random.o +sn-check-bf: sn-check-bf.c sn_network.o sn_stage.o sn_comparator.o sn_random.o + sn-cut: sn-cut.c sn_network.o sn_stage.o sn_comparator.o sn_random.o sn-evolution: sn-evolution.c sn_network.o sn_stage.o sn_comparator.o sn_population.o sn_random.o diff --git a/src/sn-check-bf.c b/src/sn-check-bf.c new file mode 100644 index 0000000..0a0dd5f --- /dev/null +++ b/src/sn-check-bf.c @@ -0,0 +1,88 @@ +/** + * collectd - src/sn-normalize.c + * Copyright (C) 2008 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 + +#include "sn_network.h" + +void exit_usage (const char *name) +{ + printf ("%s [file]\n", name); + exit (1); +} + +int main (int argc, char **argv) +{ + sn_network_t *n; + int status; + + if (argc > 2) + { + exit_usage (argv[0]); + } + else if (argc == 2) + { + if ((strcmp ("-h", argv[1]) == 0) + || (strcmp ("--help", argv[1]) == 0) + || (strcmp ("-help", argv[1]) == 0)) + exit_usage (argv[0]); + + n = sn_network_read_file (argv[1]); + } + else + { + n = sn_network_read (stdin); + } + + if (n == NULL) + { + printf ("n == NULL!\n"); + return (1); + } + + status = sn_network_brute_force_check (n); + + if (status < 0) + { + printf ("sn_network_brute_force_check failed with status %i.\n", status); + } + else if (status > 0) + { + printf ("The network does NOT sort.\n"); + } + else + { + printf ("All tests successful.\n"); + } + + return (status); +} /* int main */ + +/* vim: set shiftwidth=2 softtabstop=2 : */ -- 2.11.0