folly::encodeZigZag

ZigZag encoding that maps signed integers with a small absolute value to unsigned integers with a small (positive) values. Without this, encoding negative values using Varint would use up 9 or 10 bytes.

Synopsis

Declared in <folly/Varint.h>

uint64_t
encodeZigZag(int64_t val);

Description

if x >= 0, encodeZigZag(x) == 2*x if x < 0, encodeZigZag(x) == -2*x - 1

Return Value

The ZigZag-encoded unsigned value.

Parameters

NameDescription
valThe signed value to encode.