I feel like it's possible to have varuint64 inside a maximum of 8 bytes but nobody seems to be doing so, I'm scared

· · Web · 2 · 0 · 0

@Miaourt you need at least one extra bit than the size of the largest int that it supports though, right? otherwise some value would alias

@cyberia @ayo Yeah seems like I should be targetting 2^64-1if I want it to be variable

But even when targetting this implementations ends up with 9 bytes

A friend made me notice it was surely for performance and lexical ordering reasons

@Miaourt yeah, presumably for the same reason that booleans are stored in 8 bits

although if you're using a varint you're clearly optimising for space, so maybe bit-packing a 65-bit value isn't totally unreasonable

@Miaourt You mean, encode a uint64 value in a variable-length byte encoding of which the length is not available from its context? Intuitively, keeping the encoded form within 8 bytes for all values sounds impossible to me; both a uint64 and 8 bytes have 2^64 possible values, which leaves no room to encode the length.

Sign in to participate in the conversation

It's pronounced ʁaʁyʁe. And written RaRuRe, or R3 for short.
You can find more infos on this place by clicking there.