OSDN Git Service

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