MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeTSVector

Function EncodeTSVector

pkg/util/tsearch/encoding.go:19–49  ·  view source on GitHub ↗

EncodeTSVector encodes a tsvector into a serialized representation for on-disk storage.

(appendTo []byte, vector TSVector)

Source from the content-addressed store, hash-verified

17// EncodeTSVector encodes a tsvector into a serialized representation for
18// on-disk storage.
19func EncodeTSVector(appendTo []byte, vector TSVector) ([]byte, error) {
20 appendTo = encoding.EncodeUint32Ascending(appendTo, uint32(len(vector)))
21 for _, term := range vector {
22 l := term.lexeme
23 appendTo = encoding.EncodeUntaggedBytesValue(appendTo, encoding.UnsafeConvertStringToBytes(l))
24 if len(term.positions) > maxTSVectorPositions {
25 return nil, pgerror.Newf(pgcode.ProgramLimitExceeded,
26 "tsvector position list of size %d too large (maximum is %d)", len(term.positions),
27 maxTSVectorPositions)
28 }
29 if len(l) > maxTSVectorLexemeLen {
30 return nil, pgerror.Newf(pgcode.ProgramLimitExceeded,
31 "tsvector lexeme of size %d too large (maximum is %d)", len(l),
32 maxTSVectorLexemeLen)
33 }
34 appendTo = encoding.EncodeUint16Ascending(appendTo, uint16(len(term.positions)))
35 for _, pos := range term.positions {
36 weight, err := pos.weight.TSVectorPGEncoding()
37 if err != nil {
38 return nil, err
39 }
40 // Clear the 2 most significant bits. These should never be set,
41 // as we always make sure that positions are at most 1 << 14, but
42 // better an extra check.
43 position := pos.position & (^(uint16(3) << 14))
44 out := position | (uint16(weight) << 14)
45 appendTo = encoding.EncodeUint16Ascending(appendTo, out)
46 }
47 }
48 return appendTo, nil
49}
50
51// DecodeTSVector decodes a tsvector in disk-storage representation from the
52// input byte slice.

Callers

nothing calls this directly

Calls 6

EncodeUint32AscendingFunction · 0.92
EncodeUntaggedBytesValueFunction · 0.92
NewfFunction · 0.92
EncodeUint16AscendingFunction · 0.92
TSVectorPGEncodingMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…