Browse code

Better values for SCORE_{MIN,MAX}

SCORE_MAX is now defined as DBL_MAX
SCORE_MIN is now defined as -DBL_MAX

John Hawthorn authored on 27/07/2014 02:59:27
Showing 1 changed files

  • match.c index 1fb9bfb..68e8c3e 100644
... ...
@@ -2,11 +2,10 @@
2 2
 #include <string.h>
3 3
 #include <strings.h>
4 4
 #include <stdio.h>
5
+#include <float.h>
5 6
 
6 7
 #include "fzy.h"
7 8
 
8
-#define SCORE_MIN -1
9
-
10 9
 int has_match(const char *needle, const char *haystack){
11 10
 	while(*needle){
12 11
 		if(!*haystack)
... ...
@@ -31,6 +30,8 @@ void mat_print(int *mat, int n, int m){
31 30
 
32 31
 #define max(a, b) (((a) > (b)) ? (a) : (b))
33 32
 typedef int score_t;
33
+#define SCORE_MAX DBL_MAX
34
+#define SCORE_MIN -DBL_MAX
34 35
 
35 36
 double calculate_score(const char *needle, const char *haystack, size_t *positions){
36 37
 	if(!*haystack || !*needle)
... ...
@@ -114,7 +115,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
114 115
 
115 116
 double match_positions(const char *needle, const char *haystack, size_t *positions){
116 117
 	if(!*needle){
117
-		return 1.0;
118
+		return SCORE_MAX;
118 119
 	}else if(!has_match(needle, haystack)){
119 120
 		return SCORE_MIN;
120 121
 	}else if(!strcasecmp(needle, haystack)){
... ...
@@ -123,7 +124,7 @@ double match_positions(const char *needle, const char *haystack, size_t *positio
123 124
 			for(int i = 0; i < n; i++)
124 125
 				positions[i] = i;
125 126
 		}
126
-		return 1.0;
127
+		return SCORE_MAX;
127 128
 	}else{
128 129
 		return calculate_score(needle, haystack, positions);
129 130
 	}