Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4027181

Browse files
committed
Improve comments describing tsvector data structure.
1 parent928311a commit4027181

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

‎src/include/tsearch/ts_type.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818

1919
/*
2020
* TSVector type.
21+
*
22+
* Structure of tsvector datatype:
23+
* 1) standard varlena header
24+
* 2) int4size - 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+
*uint16number 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;
4663
typedefstruct
4764
{
4865
uint16npos;
49-
WordEntryPospos[1];/*var length */
66+
WordEntryPospos[1];/*variable length */
5067
}WordEntryPosVector;
5168

5269

@@ -60,40 +77,25 @@ typedef struct
6077
#defineMAXNUMPOS(256)
6178
#defineLIMITPOS(x) ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) )
6279

63-
/*
64-
* Structure of tsvector datatype:
65-
* 1) standard varlena header
66-
* 2) int4size - 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-
*uint16number of positions that follow.
76-
*uint16[]positions
77-
*
78-
* The positions must be sorted.
79-
*/
80-
80+
/* This struct represents a complete tsvector datum */
8181
typedefstruct
8282
{
8383
int32vl_len_;/* varlena header (do not touch directly!) */
8484
int32size;
85-
WordEntryentries[1];/*var size */
86-
/* lexemes follow */
85+
WordEntryentries[1];/*variable length */
86+
/* lexemes followthe entries[] array*/
8787
}TSVectorData;
8888

8989
typedefTSVectorData*TSVector;
9090

9191
#defineDATAHDRSIZE (offsetof(TSVectorData, entries))
92-
#defineCALCDATASIZE(x,lenstr) (DATAHDRSIZE + (x) * sizeof(WordEntry) + (lenstr) )
92+
#defineCALCDATASIZE(nentries,lenstr) (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr) )
93+
94+
/* pointer to start of a tsvector's WordEntry array */
9395
#defineARRPTR(x)( (x)->entries )
9496

95-
/*returns apointer tothe beginningoflexemes */
96-
#defineSTRPTR(x)( (char *) &(x)->entries[x->size] )
97+
/* pointer tostartofa tsvector's lexeme storage */
98+
#defineSTRPTR(x)( (char *) &(x)->entries[(x)->size] )
9799

98100
#define_POSVECPTR(x,e)((WordEntryPosVector *)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len)))
99101
#definePOSDATALEN(x,e) ( ( (e)->haspos ) ? (_POSVECPTR(x,e)->npos) : 0 )
@@ -231,7 +233,7 @@ typedef struct
231233
{
232234
int32vl_len_;/* varlena header (do not touch directly!) */
233235
int4size;/* number of QueryItems */
234-
chardata[1];
236+
chardata[1];/* data starts here */
235237
}TSQueryData;
236238

237239
typedefTSQueryData*TSQuery;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp