OSDN Git Service

Update copyright for 2020.
[pgbigm/pg_bigm.git] / bigm.h
1 /*-------------------------------------------------------------------------
2  *
3  * Portions Copyright (c) 2017-2020, pg_bigm Development Group
4  * Portions Copyright (c) 2013-2016, NTT DATA Corporation
5  * Portions Copyright (c) 2004-2012, PostgreSQL Global Development Group
6  *
7  * Changelog:
8  *       2013/01/09
9  *       Support full text search using bigrams.
10  *       Author: NTT DATA Corporation
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef __BIGM_H__
15 #define __BIGM_H__
16
17 #include "access/itup.h"
18 #include "storage/bufpage.h"
19 #include "utils/builtins.h"
20
21 /* GUC variable */
22 extern bool bigm_enable_recheck;
23 extern int      bigm_gin_key_limit;
24 extern double bigm_similarity_limit;
25 extern char     *bigm_last_update;
26
27 /* options */
28 #define LPADDING                1
29 #define RPADDING                1
30
31 /* operator strategy numbers */
32 #define LikeStrategyNumber                      1
33 #define SimilarityStrategyNumber        2
34
35 typedef struct
36 {
37         bool            pmatch;                 /* partial match is required? */
38         int8            bytelen;                /* byte length of bi-gram string */
39
40         /*
41          * Bi-gram string; we assume here that the maximum bytes for a character
42          * are four.
43          */
44         char            str[8];
45 }       bigm;
46
47 #define BIGMSIZE        sizeof(bigm)
48
49 static inline int
50 bigmstrcmp(char *arg1, int len1, char *arg2, int len2)
51 {
52         int                     i;
53         int                     len = Min(len1, len2);
54
55         for (i = 0; i < len; i++, arg1++, arg2++)
56         {
57                 if (*arg1 == *arg2)
58                         continue;
59                 if (*arg1 < *arg2)
60                         return -1;
61                 else
62                         return 1;
63         }
64
65         return (len1 == len2) ? 0 : ((len1 < len2) ? -1 : 1);
66 }
67
68 #define CMPBIGM(a,b) ( bigmstrcmp(((bigm *)a)->str, ((bigm *)a)->bytelen, ((bigm *)b)->str, ((bigm *)b)->bytelen) )
69
70 #define CPBIGM(bptr, s, len) do {               \
71         Assert(len <= 8);                               \
72         memcpy(bptr->str, s, len);              \
73         bptr->bytelen = len;                    \
74         bptr->pmatch = false;                   \
75 } while(0);
76
77 #define ISESCAPECHAR(x) (*(x) == '\\')  /* Wildcard escape character */
78 #define ISWILDCARDCHAR(x) (*(x) == '%' || *(x) == '_')  /* Wildcard
79                                                                                                                  * meta-character */
80 typedef struct
81 {
82         int32           vl_len_;                /* varlena header (do not touch directly!) */
83         char            data[1];
84 }       BIGM;
85
86 #define CALCGTSIZE(len) (VARHDRSZ + len * sizeof(bigm))
87 #define GETARR(x)               ( (bigm *)( (char*)x + VARHDRSZ ) )
88 #define ARRNELEM(x) ( ( VARSIZE(x) - VARHDRSZ )/sizeof(bigm) )
89
90 extern BIGM *generate_bigm(char *str, int slen);
91 extern BIGM *generate_wildcard_bigm(const char *str, int slen, bool *removeDups);
92
93 #endif   /* __BIGM_H__ */