MCPcopy Create free account
hub / github.com/dolthub/doltgresql / EncodeUvarintAscending

Function EncodeUvarintAscending

postgres/parser/encoding/encoding.go:217–242  ·  view source on GitHub ↗

EncodeUvarintAscending encodes the uint64 value using a variable length (length-prefixed) representation. The length is encoded as a single byte indicating the number of encoded bytes (-8) to follow. See EncodeVarintAscending for rationale. The encoded bytes are appended to the supplied buffer and t

(b []byte, v uint64)

Source from the content-addressed store, hash-verified

215// EncodeVarintAscending for rationale. The encoded bytes are appended to the
216// supplied buffer and the final buffer is returned.
217func EncodeUvarintAscending(b []byte, v uint64) []byte {
218 switch {
219 case v <= intSmall:
220 return append(b, intZero+byte(v))
221 case v <= 0xff:
222 return append(b, IntMax-7, byte(v))
223 case v <= 0xffff:
224 return append(b, IntMax-6, byte(v>>8), byte(v))
225 case v <= 0xffffff:
226 return append(b, IntMax-5, byte(v>>16), byte(v>>8), byte(v))
227 case v <= 0xffffffff:
228 return append(b, IntMax-4, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
229 case v <= 0xffffffffff:
230 return append(b, IntMax-3, byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8),
231 byte(v))
232 case v <= 0xffffffffffff:
233 return append(b, IntMax-2, byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16),
234 byte(v>>8), byte(v))
235 case v <= 0xffffffffffffff:
236 return append(b, IntMax-1, byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24),
237 byte(v>>16), byte(v>>8), byte(v))
238 default:
239 return append(b, IntMax, byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32),
240 byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
241 }
242}
243
244// EncodeUvarintDescending encodes the uint64 value so that it sorts in
245// reverse order, from largest to smallest.

Callers 2

encodeVarExpNumberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected