18
18
19
19
/*
20
20
* TSVector type.
21
+ *
22
+ * Structure of tsvector datatype:
23
+ * 1) standard varlena header
24
+ * 2) int4 size - number of lexemes (WordEntry array entries)
25
+ * 3) Array of WordEntry - one per lexeme; must be sorted according to
26
+ * tsCompareString() (ie, memcmp of lexeme strings).
27
+ * WordEntry->pos gives the number of bytes from end of WordEntry
28
+ * array to start of lexeme's string, which is of length len.
29
+ * 4) Per-lexeme data storage:
30
+ * lexeme string (not null-terminated)
31
+ * if haspos is true:
32
+ * padding byte if necessary to make the position data 2-byte aligned
33
+ * uint16 number of positions that follow
34
+ * WordEntryPos[] positions
35
+ *
36
+ * The positions for each lexeme must be sorted.
37
+ *
21
38
* Note, tsvectorsend/recv believe that sizeof(WordEntry) == 4
22
39
*/
23
40
@@ -46,7 +63,7 @@ typedef uint16 WordEntryPos;
46
63
typedef struct
47
64
{
48
65
uint16 npos ;
49
- WordEntryPos pos [1 ]; /* var length */
66
+ WordEntryPos pos [1 ]; /* variable length */
50
67
} WordEntryPosVector ;
51
68
52
69
@@ -60,40 +77,25 @@ typedef struct
60
77
#define MAXNUMPOS (256)
61
78
#define LIMITPOS (x ) ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) )
62
79
63
- /*
64
- * Structure of tsvector datatype:
65
- * 1) standard varlena header
66
- * 2) int4 size - number of lexemes or WordEntry array, which is the same
67
- * 3) Array of WordEntry - sorted array, comparison based on word's length
68
- * and strncmp(). WordEntry->pos points number of
69
- * bytes from end of WordEntry array to start of
70
- * corresponding lexeme.
71
- * 4) Lexeme's storage:
72
- * lexeme (without null-terminator)
73
- * if haspos is true:
74
- * padding byte if necessary to make the number of positions 2-byte aligned
75
- * uint16 number of positions that follow.
76
- * uint16[] positions
77
- *
78
- * The positions must be sorted.
79
- */
80
-
80
+ /* This struct represents a complete tsvector datum */
81
81
typedef struct
82
82
{
83
83
int32 vl_len_ ; /* varlena header (do not touch directly!) */
84
84
int32 size ;
85
- WordEntry entries [1 ]; /* var size */
86
- /* lexemes follow */
85
+ WordEntry entries [1 ]; /* variable length */
86
+ /* lexemes follow the entries[] array */
87
87
} TSVectorData ;
88
88
89
89
typedef TSVectorData * TSVector ;
90
90
91
91
#define DATAHDRSIZE (offsetof(TSVectorData, entries))
92
- #define CALCDATASIZE (x , lenstr ) (DATAHDRSIZE + (x) * sizeof(WordEntry) + (lenstr) )
92
+ #define CALCDATASIZE (nentries , lenstr ) (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr) )
93
+
94
+ /* pointer to start of a tsvector's WordEntry array */
93
95
#define ARRPTR (x ) ( (x)->entries )
94
96
95
- /* returns a pointer to the beginning of lexemes */
96
- #define STRPTR (x ) ( (char *) &(x)->entries[x ->size] )
97
+ /* pointer to start of a tsvector's lexeme storage */
98
+ #define STRPTR (x ) ( (char *) &(x)->entries[(x) ->size] )
97
99
98
100
#define _POSVECPTR (x , e ) ((WordEntryPosVector *)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len)))
99
101
#define POSDATALEN (x ,e ) ( ( (e)->haspos ) ? (_POSVECPTR(x,e)->npos) : 0 )
@@ -231,7 +233,7 @@ typedef struct
231
233
{
232
234
int32 vl_len_ ; /* varlena header (do not touch directly!) */
233
235
int4 size ; /* number of QueryItems */
234
- char data [1 ];
236
+ char data [1 ]; /* data starts here */
235
237
} TSQueryData ;
236
238
237
239
typedef TSQueryData * TSQuery ;
0 commit comments