OSDN Git Service

Add the news about the release of RPM files.
[pgbigm/pg_bigm.git] / bigm.h
diff --git a/bigm.h b/bigm.h
index e426711..aa01aa8 100644 (file)
--- a/bigm.h
+++ b/bigm.h
@@ -1,11 +1,13 @@
 /*-------------------------------------------------------------------------
  *
+ * Portions Copyright (c) 2017-2020, pg_bigm Development Group
+ * Portions Copyright (c) 2013-2016, NTT DATA Corporation
  * Portions Copyright (c) 2004-2012, PostgreSQL Global Development Group
  *
  * Changelog:
- *   2013/01/09
- *   Support full text search using bigrams.
- *   Author: NTT DATA Corporation
+ *      2013/01/09
+ *      Support full text search using bigrams.
+ *      Author: NTT DATA Corporation
  *
  *-------------------------------------------------------------------------
  */
 #include "utils/builtins.h"
 
 /* GUC variable */
-extern bool    bigm_enable_recheck;
+extern bool bigm_enable_recheck;
 extern int     bigm_gin_key_limit;
+extern double bigm_similarity_limit;
+extern char    *bigm_last_update;
 
 /* options */
 #define LPADDING               1
@@ -26,21 +30,41 @@ extern int  bigm_gin_key_limit;
 
 /* operator strategy numbers */
 #define LikeStrategyNumber                     1
+#define SimilarityStrategyNumber       2
 
 typedef struct
 {
-       bool    pmatch;         /* partial match is required? */
-       int             bytelen;        /* byte length of bi-gram string */
+       bool            pmatch;                 /* partial match is required? */
+       int8            bytelen;                /* byte length of bi-gram string */
+
        /*
-        * Bi-gram string; we assume here that the maximum bytes for
-        * a character are four.
+        * Bi-gram string; we assume here that the maximum bytes for a character
+        * are four.
         */
-       char    str[8];
-} bigm;
+       char            str[8];
+}      bigm;
 
 #define BIGMSIZE       sizeof(bigm)
 
-int    bigmstrcmp(char *arg1, int len1, char *arg2, int len2);
+static inline int
+bigmstrcmp(char *arg1, int len1, char *arg2, int len2)
+{
+       int                     i;
+       int                     len = Min(len1, len2);
+
+       for (i = 0; i < len; i++, arg1++, arg2++)
+       {
+               if (*arg1 == *arg2)
+                       continue;
+               if (*arg1 < *arg2)
+                       return -1;
+               else
+                       return 1;
+       }
+
+       return (len1 == len2) ? 0 : ((len1 < len2) ? -1 : 1);
+}
+
 #define CMPBIGM(a,b) ( bigmstrcmp(((bigm *)a)->str, ((bigm *)a)->bytelen, ((bigm *)b)->str, ((bigm *)b)->bytelen) )
 
 #define CPBIGM(bptr, s, len) do {              \
@@ -57,13 +81,13 @@ typedef struct
 {
        int32           vl_len_;                /* varlena header (do not touch directly!) */
        char            data[1];
-} BIGM;
+}      BIGM;
 
 #define CALCGTSIZE(len) (VARHDRSZ + len * sizeof(bigm))
 #define GETARR(x)              ( (bigm *)( (char*)x + VARHDRSZ ) )
 #define ARRNELEM(x) ( ( VARSIZE(x) - VARHDRSZ )/sizeof(bigm) )
 
-BIGM      *generate_bigm(char *str, int slen);
-BIGM      *generate_wildcard_bigm(const char *str, int slen, bool *removeDups);
+extern BIGM *generate_bigm(char *str, int slen);
+extern BIGM *generate_wildcard_bigm(const char *str, int slen, bool *removeDups);
 
 #endif   /* __BIGM_H__ */