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

Function DecodeTSVector

pkg/util/tsearch/encoding.go:53–90  ·  view source on GitHub ↗

DecodeTSVector decodes a tsvector in disk-storage representation from the input byte slice.

(b []byte)

Source from the content-addressed store, hash-verified

51// DecodeTSVector decodes a tsvector in disk-storage representation from the
52// input byte slice.
53func DecodeTSVector(b []byte) (ret TSVector, err error) {
54 var nTerms uint32
55 var nPositions, position uint16
56 b, nTerms, err = encoding.DecodeUint32Ascending(b)
57 if err != nil {
58 return nil, err
59 }
60 ret = make([]tsTerm, nTerms)
61 for i := uint32(0); i < nTerms; i++ {
62 var lexeme []byte
63 b, lexeme, err = encoding.DecodeUntaggedBytesValue(b)
64 if err != nil {
65 return nil, err
66 }
67 b, nPositions, err = encoding.DecodeUint16Ascending(b)
68 if err != nil {
69 return nil, err
70 }
71 term := &ret[i]
72 term.lexeme = string(lexeme)
73 term.positions = make([]tsPosition, nPositions)
74 for j := uint16(0); j < nPositions; j++ {
75 b, position, err = encoding.DecodeUint16Ascending(b)
76 if err != nil {
77 return nil, err
78 }
79 encodedWeight := position >> 14
80 weight, err := tsWeightFromVectorPGEncoding(byte(encodedWeight))
81 if err != nil {
82 return nil, err
83 }
84 // Clear the 2 most significant bits (they were used for the weight).
85 position = position & (^(uint16(3) << 14))
86 term.positions[j] = tsPosition{position: position, weight: weight}
87 }
88 }
89 return ret, nil
90}
91
92// EncodeTSVectorPGBinary encodes a tsvector into a serialized representation
93// that's identical to Postgres's wire protocol representation.

Callers

nothing calls this directly

Calls 4

DecodeUint32AscendingFunction · 0.92
DecodeUntaggedBytesValueFunction · 0.92
DecodeUint16AscendingFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…