Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

array

import array

This module provides fixed-width typed array classes: twos- complement integers (Int8Array/UInt8Array through Int64Array/UInt64Array) and IEEE-754 floating-point numbers (FloatArray, DoubleArray), each storing its elements packed in the platform byte order. They complement the bytes object and allow higher-level binary data manipulation without giving up direct access to the underlying bytes (to_bytes()).

All ten classes share the same interface (indexing, append()/ insert()/remove_at()/set()/pop(), slice(), fill(), equals(), iteration via for x in arr, and conversion via to_list()/to_bytes()): see [[array.Int16Array]] for the fully documented shape every other class in this module follows.

Int64Array/UInt64Array accept and return bigint values (in addition to plain integers) for anything past what a regular number can hold exactly: see is_bigint().

Example

import array

var a = array.Int32Array([1, 2, 3])
a.append(4)
for x in a {
  echo x
}
echo a.slice(1, 3).to_list()   # [2, 3]

The array API

Every public name in array, wherever it is declared. Each links to the page that documents it.

NameKindSummary
array.DOUBLE_MAXconstantMaximum value that “should” exist in a list passed to DoubleArray.
array.DOUBLE_MINconstantMinimum value that “should” exist in a list passed to DoubleArray.
array.DoubleArrayclassclass DoubleArray represents an array of 64-bit IEEE-754 floating-point numbers (doubles) in the platform…
array.FLOAT_MAXconstantMaximum value that “should” exist in a list passed to FloatArray.
array.FLOAT_MINconstantMinimum value that “should” exist in a list passed to FloatArray.
array.FloatArrayclassclass FloatArray represents an array of 32-bit IEEE-754 floating-point numbers in the platform byte order.
array.INT16_MAXconstantMaximum value that “should” exist in a list passed to Int16Array.
array.INT16_MINconstantMinimum value that “should” exist in a list passed to Int16Array.
array.INT32_MAXconstantMaximum value that “should” exist in a list passed to Int32Array.
array.INT32_MINconstantMinimum value that “should” exist in a list passed to Int32Array.
array.INT64_MAXconstantMaximum value that “should” exist in a list passed to Int64Array.
array.INT64_MINconstantMinimum value that “should” exist in a list passed to Int64Array.
array.INT8_MAXconstantMaximum value that “should” exist in a list passed to Int8Array.
array.INT8_MINconstantMinimum value that “should” exist in a list passed to Int8Array.
array.Int16Arrayclassclass Int16Array represents an array of twos-complement 16-bit signed integers in the platform byte order.
array.Int32Arrayclassclass Int32Array represents an array of twos-complement 32-bit signed integers in the platform byte order.
array.Int64Arrayclassclass Int64Array represents an array of twos-complement 64-bit signed integers in the platform byte order.
array.Int8Arrayclassclass Int8Array represents an array of twos-complement 8-bit signed integers.
array.UINT16_MAXconstantMaximum value that “should” exist in a list passed to UInt16Array.
array.UINT32_MAXconstantMaximum value that “should” exist in a list passed to UInt32Array.
array.UINT64_MAXconstantMaximum value that “should” exist in a list passed to UInt64Array.
array.UINT8_MAXconstantMaximum value that “should” exist in a list passed to UInt8Array.
array.UInt16Arrayclassclass UInt16Array represents an array of twos-complement 16-bit unsigned integers in the platform byte order.
array.UInt32Arrayclassclass UInt32Array represents an array of twos-complement 32-bit unsigned integers in the platform byte order.
array.UInt64Arrayclassclass UInt64Array represents an array of twos-complement 64-bit unsigned integers in the platform byte order.
array.UInt8Arrayclassclass UInt8Array represents an array of twos-complement 8-bit unsigned integers.

Submodules

ModuleReached asSummary
array.doublearray.*DoubleArray: a packed array of double-precision IEEE 754 floats, 8 bytes per element.
array.floatarray.*FloatArray: a packed array of single-precision IEEE 754 floats, 4 bytes per element.
array.int16array.*Int16Array: a packed array of twos-complement 16-bit signed integers, 2 bytes per element.
array.int32array.*Int32Array: a packed array of twos-complement 32-bit signed integers, 4 bytes per element.
array.int64array.*Int64Array: a packed array of twos-complement 64-bit signed integers, 8 bytes per element.
array.int8array.*Int8Array: a packed array of twos-complement 8-bit signed integers, 1 byte per element.
array.uint16array.*UInt16Array: a packed array of unsigned 16-bit integers, 2 bytes per element.
array.uint32array.*UInt32Array: a packed array of unsigned 32-bit integers, 4 bytes per element.
array.uint64array.*UInt64Array: a packed array of unsigned 64-bit integers, 8 bytes per element.
array.uint8array.*UInt8Array: a packed array of unsigned 8-bit integers, 1 byte per element.

2022, Richard Ore and The Zuri Contributors