OSDN Git Service

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