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.

Parameters

DestinationType

deep element type of the result slice.

Return Value

Type: auto

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