summaryrefslogtreecommitdiff
path: root/src/c/auxiliaryFunctions/find
diff options
context:
space:
mode:
Diffstat (limited to 'src/c/auxiliaryFunctions/find')
-rw-r--r--src/c/auxiliaryFunctions/find/cfinda.c4
-rw-r--r--src/c/auxiliaryFunctions/find/dfinda.c4
-rw-r--r--src/c/auxiliaryFunctions/find/sfinda.c4
-rw-r--r--src/c/auxiliaryFunctions/find/zfinda.c4
4 files changed, 12 insertions, 4 deletions
diff --git a/src/c/auxiliaryFunctions/find/cfinda.c b/src/c/auxiliaryFunctions/find/cfinda.c
index f846ce50..819d423b 100644
--- a/src/c/auxiliaryFunctions/find/cfinda.c
+++ b/src/c/auxiliaryFunctions/find/cfinda.c
@@ -12,7 +12,7 @@
#include "find.h"
-void cfinda(floatComplex* z, int size, float *out, int *indiceOut) {
+void cfinda(floatComplex* z, int size, float *out, int *indiceOut , int max) {
int i = 0;
indiceOut[1]=0;
@@ -20,6 +20,8 @@ void cfinda(floatComplex* z, int size, float *out, int *indiceOut) {
out[0]=-1;
for (i = 0; i < size ; ++i) {
+ /*to avoid useless search if we only want to find the max first founded value */
+ if (indiceOut[1] == max ) return ;
if (creals(z[i]) != 0 || cimags(z[i]) != 0) {
out[indiceOut[1]] = (float)(i+1);
indiceOut[1]++;
diff --git a/src/c/auxiliaryFunctions/find/dfinda.c b/src/c/auxiliaryFunctions/find/dfinda.c
index 986be373..1f07b674 100644
--- a/src/c/auxiliaryFunctions/find/dfinda.c
+++ b/src/c/auxiliaryFunctions/find/dfinda.c
@@ -13,7 +13,7 @@
#include "find.h"
-void dfinda(double* x, int size ,double *out, int *indiceOut) {
+void dfinda(double* x, int size ,double *out, int *indiceOut , int max ) {
int i = 0;
indiceOut[1]=0;
@@ -22,6 +22,8 @@ void dfinda(double* x, int size ,double *out, int *indiceOut) {
for (i = 0; i < size ; ++i) {
+ /*to avoid useless search if we only want to find the max first founded value */
+ if (indiceOut[1] == max ) return ;
if (x[i] != 0) {
out[indiceOut[1]] = (double)(i+1);
indiceOut[1]++;
diff --git a/src/c/auxiliaryFunctions/find/sfinda.c b/src/c/auxiliaryFunctions/find/sfinda.c
index 6a23a9dd..73c86d37 100644
--- a/src/c/auxiliaryFunctions/find/sfinda.c
+++ b/src/c/auxiliaryFunctions/find/sfinda.c
@@ -12,7 +12,7 @@
#include "find.h"
-void sfinda(float* x, int size, float* out, int *indiceOut) {
+void sfinda(float* x, int size, float* out, int *indiceOut , int max ) {
int i = 0;
indiceOut[1]=0;
@@ -22,6 +22,8 @@ void sfinda(float* x, int size, float* out, int *indiceOut) {
for (i = 0; i < size ; ++i) {
+ /*to avoid useless search if we only want to find the max first founded value */
+ if (indiceOut[1] == max ) return ;
if (x[i] != 0) {
out[indiceOut[1]] = (float)(i+1);
indiceOut[1]++;
diff --git a/src/c/auxiliaryFunctions/find/zfinda.c b/src/c/auxiliaryFunctions/find/zfinda.c
index f9c3f970..0fa7e178 100644
--- a/src/c/auxiliaryFunctions/find/zfinda.c
+++ b/src/c/auxiliaryFunctions/find/zfinda.c
@@ -12,7 +12,7 @@
#include "find.h"
-void zfinda(doubleComplex* z, int size, double *out, int* indiceOut) {
+void zfinda(doubleComplex* z, int size, double *out, int* indiceOut, int max ) {
int i = 0;
indiceOut[1]=0;
@@ -20,6 +20,8 @@ void zfinda(doubleComplex* z, int size, double *out, int* indiceOut) {
out[0]=-1;
for (i = 0; i < size ; ++i) {
+ /*to avoid useless search if we only want to find the max first founded value */
+ if (indiceOut[1] == max ) return ;
if (zreals(z[i]) != 0 || zimags(z[i]) != 0) {
out[indiceOut[1]] = (double)(i+1);
indiceOut[1]++;