The OpenD Programming Language

bitpack

Bitpack slice over an integral slice.

Bitpack is used to represent unsigned integer slice with fewer number of bits in integer binary representation.

  1. auto bitpack(Slice!(Iterator, N, kind) slice)
    bitpack
    (
    size_t pack
    Iterator
    size_t N
    SliceKind kind
    I = typeof(Iterator.init[size_t.init])
    )
    (
    Slice!(Iterator, N, kind) slice
    )
    if (
    __traits(isIntegral, I) &&
    (
    kind == Contiguous ||
    kind == Canonical
    )
    &&
    pack > 1
    )
  2. auto bitpack(T[] array)
  3. auto bitpack(T withAsSlice)

Parameters

pack

counts of bits in the integer.

slice Slice!(Iterator, N, kind)

a contiguous or canonical slice on top of integral iterator.

Return Value

Type: auto

A bitpack slice.

Examples

size_t[10] data;
// creates a packed unsigned integer slice with max allowed value equal to `2^^6 - 1 == 63`.
auto packs = data[].bitpack!6;
assert(packs.length == data.length * size_t.sizeof * 8 / 6);
packs[$ - 1] = 24;
assert(packs[$ - 1] == 24);

packs.popFront;
assert(packs[$ - 1] == 24);

Meta