1818
1919/*
2020 * 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+ *
2138 * Note, tsvectorsend/recv believe that sizeof(WordEntry) == 4
2239 */
2340
@@ -46,7 +63,7 @@ typedef uint16 WordEntryPos;
4663typedef struct
4764{
4865 uint16 npos ;
49- WordEntryPos pos [1 ]; /* var length */
66+ WordEntryPos pos [1 ]; /* variable length */
5067} WordEntryPosVector ;
5168
5269
@@ -60,40 +77,25 @@ typedef struct
6077#define MAXNUMPOS (256)
6178#define LIMITPOS (x ) ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) )
6279
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 */
8181typedef struct
8282{
8383 int32 vl_len_ ; /* varlena header (do not touch directly!) */
8484 int32 size ;
85- WordEntry entries [1 ]; /* var size */
86- /* lexemes follow */
85+ WordEntry entries [1 ]; /* variable length */
86+ /* lexemes follow the entries[] array */
8787} TSVectorData ;
8888
8989typedef TSVectorData * TSVector ;
9090
9191#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 */
9395#define ARRPTR (x ) ( (x)->entries )
9496
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] )
9799
98100#define _POSVECPTR (x , e ) ((WordEntryPosVector *)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len)))
99101#define POSDATALEN (x ,e ) ( ( (e)->haspos ) ? (_POSVECPTR(x,e)->npos) : 0 )
@@ -231,7 +233,7 @@ typedef struct
231233{
232234 int32 vl_len_ ; /* varlena header (do not touch directly!) */
233235 int4 size ; /* number of QueryItems */
234- char data [1 ];
236+ char data [1 ]; /* data starts here */
235237} TSQueryData ;
236238
237239typedef TSQueryData * TSQuery ;
0 commit comments