The OpenD Programming Language

bytegroup

Bytegroup slice over an integral slice.

Groups existing slice into fixed length chunks and uses them as data store for destination type.

Correctly handles scalar types on both little-endian and big-endian platforms.

  1. Slice!(BytegroupIterator!(Iterator, group, DestinationType), N, kind) bytegroup(Slice!(Iterator, N, kind) slice)
    Slice!(BytegroupIterator!(Iterator, group, DestinationType), N, kind)
    bytegroup
    (
    size_t group
    DestinationType
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) slice
    )
    if (
    (
    kind == Contiguous ||
    kind == Canonical
    )
    &&
    group
    )
  2. auto bytegroup(T[] array)
  3. auto bytegroup(T withAsSlice)

Parameters

group

count of iterator items used to store the destination type.

DestinationType

deep element type of the result slice.

slice Slice!(Iterator, N, kind)

a contiguous or canonical slice.

Return Value

Type: Slice!(BytegroupIterator!(Iterator, group, DestinationType), N, kind)

A bytegroup slice.

Examples

24 bit integers

import mir.ndslice.slice: DeepElementType, sliced;

ubyte[20] data;
// creates a packed unsigned integer slice with max allowed value equal to `2^^6 - 1 == 63`.
auto int24ar = data[].bytegroup!(3, int); // 24 bit integers
assert(int24ar.length == data.length / 3);

enum checkInt = ((1 << 20) - 1);

int24ar[3] = checkInt;
assert(int24ar[3] == checkInt);

int24ar.popFront;
assert(int24ar[2] == checkInt);

static assert(is(DeepElementType!(typeof(int24ar)) == int));

48 bit integers

import mir.ndslice.slice: DeepElementType, sliced;
ushort[20] data;
// creates a packed unsigned integer slice with max allowed value equal to `2^^6 - 1 == 63`.
auto int48ar = data[].sliced.bytegroup!(3, long); // 48 bit integers
assert(int48ar.length == data.length / 3);

enum checkInt = ((1L << 44) - 1);

int48ar[3] = checkInt;
assert(int48ar[3] == checkInt);

int48ar.popFront;
assert(int48ar[2] == checkInt);

static assert(is(DeepElementType!(typeof(int48ar)) == long));

Meta