[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [labplot] src/backend/nsl: added sorting function to nsl ad use it
From:       Stefan Gerlach <stefan.gerlach () uni-konstanz ! de>
Date:       2016-08-31 21:19:12
Message-ID: E1bfCue-0007gj-J4 () code ! kde ! org
[Download RAW message or body]

Git commit 1bb1f753a8892fe9173f26e5d1ecc3d2077e1e8f by Stefan Gerlach.
Committed on 31/08/2016 at 21:19.
Pushed by sgerlach into branch 'master'.

added sorting function to nsl ad use it

M  +1    -1    src/backend/nsl/Makefile
M  +2    -11   src/backend/nsl/nsl_geom_linesim.c
A  +43   -0    src/backend/nsl/nsl_sort.c     [License: GPL (v2+)]
A  +40   -0    src/backend/nsl/nsl_sort.h     [License: GPL (v2+)]

http://commits.kde.org/labplot/1bb1f753a8892fe9173f26e5d1ecc3d2077e1e8f

diff --git a/src/backend/nsl/Makefile b/src/backend/nsl/Makefile
index ed43226..54458c8 100644
--- a/src/backend/nsl/Makefile
+++ b/src/backend/nsl/Makefile
@@ -21,7 +21,7 @@ nsl_filter_test: nsl_filter_test.c nsl_filter.c nsl_sf_poly.c
 	gcc -o $@ $^ -lm -lgsl -lgslcblas
 nsl_filter_test_fftw: nsl_filter_test.c nsl_filter.c nsl_sf_poly.c
 	gcc -o $@ $^ -lm -DHAVE_FFTW3 -lfftw3 -lgsl -lgslcblas
-nsl_geom_linesim_test: nsl_geom_linesim_test.c nsl_geom_linesim.c nsl_geom.c
+nsl_geom_linesim_test: nsl_geom_linesim_test.c nsl_geom_linesim.c nsl_geom.c nsl_sort.c
 	gcc -o $@ $^ -lm
 
 clean:
diff --git a/src/backend/nsl/nsl_geom_linesim.c b/src/backend/nsl/nsl_geom_linesim.c
index 0d3c9ae..6bb0592 100644
--- a/src/backend/nsl/nsl_geom_linesim.c
+++ b/src/backend/nsl/nsl_geom_linesim.c
@@ -28,7 +28,6 @@
 
 /*
 	TODO:
-	* extern nsl_compare
 	* non-parametric functions (calculate eps from data)
 	* more algorithm
 	* error calculation by area
@@ -38,6 +37,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "nsl_sort.h"
 #include "nsl_geom.h"
 #include "nsl_geom_linesim.h"
 
@@ -310,16 +310,7 @@ size_t nsl_geom_linesim_douglas_peucker(const double xdata[], const double ydata
 		index[nout++] = n-1;
 
 	/* sort array index */
-	/* TODO: put in extra file */
-	int nsl_compare(const void* a, const void* b) {
-		size_t _a = * ( (size_t*) a );
-		size_t _b = * ( (size_t*) b );
-
-		// an easy expression for comparing
-		return (_a > _b) - (_a < _b);
-	}
-
-	qsort(index, nout, sizeof(size_t), nsl_compare);
+	nsl_sort_size_t(index, nout);
 
 	return nout;
 }
diff --git a/src/backend/nsl/nsl_sort.c b/src/backend/nsl/nsl_sort.c
new file mode 100644
index 0000000..b3593be
--- /dev/null
+++ b/src/backend/nsl/nsl_sort.c
@@ -0,0 +1,43 @@
+/***************************************************************************
+    File                 : nsl_sort.c
+    Project              : LabPlot
+    Description          : NSL sorting functions
+    --------------------------------------------------------------------
+    Copyright            : (C) 2016 by Stefan Gerlach (stefan.gerlach@uni.kn)
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *  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; either version 2 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.                           *
+ *                                                                         *
+ *   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 Street, Fifth Floor,                    *
+ *   Boston, MA  02110-1301  USA                                           *
+ *                                                                         *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include "nsl_sort.h"
+
+int nsl_sort_compare_size_t(const void* a, const void* b) {
+	size_t _a = * ( (size_t*) a );
+	size_t _b = * ( (size_t*) b );
+
+	/* an easy expression for comparing */
+	return (_a > _b) - (_a < _b);
+}
+
+void nsl_sort_size_t(size_t array[], const size_t n) {
+	qsort(array, n, sizeof(size_t), nsl_sort_compare_size_t);
+}
+
diff --git a/src/backend/nsl/nsl_sort.h b/src/backend/nsl/nsl_sort.h
new file mode 100644
index 0000000..050baa5
--- /dev/null
+++ b/src/backend/nsl/nsl_sort.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+    File                 : nsl_sort.h
+    Project              : LabPlot
+    Description          : NSL sorting functions
+    --------------------------------------------------------------------
+    Copyright            : (C) 2016 by Stefan Gerlach (stefan.gerlach@uni.kn)
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *  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; either version 2 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.                           *
+ *                                                                         *
+ *   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 Street, Fifth Floor,                    *
+ *   Boston, MA  02110-1301  USA                                           *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef NSL_SORT_H
+#define NSL_SORT_H
+
+#include <stdlib.h>
+
+/* compare size_t objects */
+int nsl_sort_compare_size_t(const void* a, const void* b); 
+
+/* sort size_t array of size n */
+void nsl_sort_size_t(size_t array[], const size_t n);
+
+#endif /* NSL_SORT_H */
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic