zigzagEncode
Maps a signed 64-bit integer to an unsigned one so that values near zero stay small (0, -1, 1, -2 become 0, 1, 2, 3): the “zigzag” mapping of Protocol Buffers, used before writing a signed
value as a varint.
Available since v3.1.8
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | bigint | A signed integer in the 64-bit range |
Returns
Section titled “Returns”bigint — The unsigned zigzag value
Examples
Section titled “Examples”Keep small negative numbers small
Section titled “Keep small negative numbers small”Zigzag interleaves negatives and positives, so a varint stays short for values near zero.
Cover the whole signed 64-bit range
Section titled “Cover the whole signed 64-bit range”The most negative value maps to the largest unsigned one.
