Link Search Menu Expand Document

array

This moddule provides multiple classes for working with arrays of twos-complement integers in the platform byte order. The classes provided in this module complement the bytes() object and allow higher other binary data manipulation.

Properties


array.INT16_MAX
Maximum value that “should” exist in a list passed to Int16Array.
array.UINT16_MAX
Maximum value that “should” exist in a list passed to UInt16Array.
array.INT32_MAX
Maximum value that “should” exist in a list passed to Int32Array.
array.UINT32_MAX
Maximum value that “should” exist in a list passed to UInt32Array.
array.INT64_MAX
Maximum value that “should” exist in a list passed to Int64Array.
array.UINT64_MAX
Maximum value that “should” exist in a list passed to UInt64Array.
array.INT16_MIN
Minimum value that “should” exist in a list passed to Int16Array.
array.INT32_MIN
Minimum value that “should” exist in a list passed to Int32Array.
array.INT64_MIN
Minimum value that “should” exist in a list passed to Int64Array.

Classes


class Int16Array


class Int16Array represents an array of twos-complement 16-bit signed integers in the platform byte order.

@printable @iterable @serializable

class Int16Array methods


Int16Array(n: number | list)
  • If n is a number, it creates a new Int16Array that can hold up to n number of elements, but with all the elements set to 0.
  • If n is a list, it creates a new Int16Array with its elements set to the values in the list.
constructor
length()
Returns the number of items in the array.
bytes_length()
Returns the length of the array if it were to be converted to bytes.
first()
Returns the first item in the array or nil if the array is empty.
last()
Returns the last item in the array or nil if the array is empty.
append(value: int)
Adds the given value to the end of the array.
get(index: number)
Returns the number at the specified index in the array. If index is outside the boundary of the array indexes (0..(array.length() - 1)), an exception is thrown.
return number
extend(array: Int16Array)
Updates the content of the current array by appending all the contents of array to the end of the array in exact order.
reverse()
Returns a new array containing the elements in the original array in reverse order.
clone()
Returns a new Int16Array containing all items from the current array. The new array is a shallow copy of the original array.
return Int16Array
pop()
Removes the last element in the array and returns the value of that item.
return number
to_bytes()
Returns the array as a bytes object
return bytes
to_list()
Returns the elements of the array as a list of numbers
return list
to_string()
Returns a string representation of the array
return string
get_pointer()
Returns the raw int16 array pointer.
return ptr

class Int32Array


class Int32Array represents an array of twos-complement 32-bit signed integers in the platform byte order.

@printable @iterable @serializable

class Int32Array methods


Int32Array(n: number | list)
  • If n is a number, it creates a new Int32Array that can hold up to n number of elements, but with all the elements set to 0.
  • If n is a list, it creates a new Int32Array with its elements set to the values in the list.
constructor
length()
Returns the number of items in the array.
bytes_length()
Returns the length of the array if it were to be converted to bytes.
first()
Returns the first item in the array or nil if the array is empty.
last()
Returns the last item in the array or nil if the array is empty.
append(value: int)
Adds the given value to the end of the array.
get(index: number)
Returns the number at the specified index in the array. If index is outside the boundary of the array indexes (0..(array.length() - 1)), an exception is thrown.
return number
extend(array: Int32Array)
Updates the content of the current array by appending all the contents of array to the end of the array in exact order.
reverse()
Returns a new array containing the elements in the original array in reverse order.
clone()
Returns a new Int32Array containing all items from the current array. The new array is a shallow copy of the original array.
return Int32Array
pop()
Removes the last element in the array and returns the value of that item.
return number
to_bytes()
Returns the array as a bytes object
return bytes
to_list()
Returns the elements of the array as a list of numbers
return list
to_string()
Returns a string representation of the array
return string
get_pointer()
Returns the raw int32 array pointer.
return ptr

class Int64Array


class Int64Array represents an array of twos-complement 64-bit signed integers in the platform byte order.

@printable @iterable @serializable

class Int64Array methods


Int64Array(n: number | list)
  • If n is a number, it creates a new Int64Array that can hold up to n number of elements, but with all the elements set to 0.
  • If n is a list, it creates a new Int64Array with its elements set to the values in the list.
constructor
length()
Returns the number of items in the array.
bytes_length()
Returns the length of the array if it were to be converted to bytes.
first()
Returns the first item in the array or nil if the array is empty.
last()
Returns the last item in the array or nil if the array is empty.
append(value: int)
Adds the given value to the end of the array.
get(index: number)
Returns the number at the specified index in the array. If index is outside the boundary of the array indexes (0..(array.length() - 1)), an exception is thrown.
return number
extend(array: Int64Array)
Updates the content of the current array by appending all the contents of array to the end of the array in exact order.
reverse()
Returns a new array containing the elements in the original array in reverse order.
clone()
Returns a new Int64Array containing all items from the current array. The new array is a shallow copy of the original array.
return Int64Array
pop()
Removes the last element in the array and returns the value of that item.
return number
to_bytes()
Returns the array as a bytes object
return bytes
to_list()
Returns the elements of the array as a list of numbers
return list
to_string()
Returns a string representation of the array
return string
get_pointer()
Returns the raw int64 array pointer.
return ptr

class UInt16Array


class UInt16Array represents an array of twos-complement 16-bit unsigned integers in the platform byte order.

@printable @iterable @serializable

class UInt16Array methods


UInt16Array(n: number | list)
  • If n is a number, it creates a new UInt16Array that can hold up to n number of elements, but with all the elements set to 0.
  • If n is a list, it creates a new UInt16Array with its elements set to the values in the list.
constructor
length()
Returns the number of items in the array.
bytes_length()
Returns the length of the array if it were to be converted to bytes.
first()
Returns the first item in the array or nil if the array is empty.
last()
Returns the last item in the array or nil if the array is empty.
append(value: int)
Adds the given value to the end of the array.
get(index: number)
Returns the number at the specified index in the array. If index is outside the boundary of the array indexes (0..(array.length() - 1)), an exception is thrown.
return number
extend(array: UInt16Array)
Updates the content of the current array by appending all the contents of array to the end of the array in exact order.
reverse()
Returns a new array containing the elements in the original array in reverse order.
clone()
Returns a new UInt16Array containing all items from the current array. The new array is a shallow copy of the original array.
return UInt16Array
pop()
Removes the last element in the array and returns the value of that item.
return number
to_bytes()
Returns the array as a bytes object
return bytes
to_list()
Returns the elements of the array as a list of numbers
return list
to_string()
Returns a string representation of the array
return string
get_pointer()
Returns the raw uint16 array pointer.
return ptr

class UInt32Array


class UInt32Array represents an array of twos-complement 32-bit unsigned integers in the platform byte order.

@printable @iterable @serializable

class UInt32Array methods


UInt32Array(n: number | list)
  • If n is a number, it creates a new UInt32Array that can hold up to n number of elements, but with all the elements set to 0.
  • If n is a list, it creates a new UInt32Array with its elements set to the values in the list.
constructor
length()
Returns the number of items in the array.
bytes_length()
Returns the length of the array if it were to be converted to bytes.
first()
Returns the first item in the array or nil if the array is empty.
last()
Returns the last item in the array or nil if the array is empty.
append(value: int)
Adds the given value to the end of the array.
get(index: number)
Returns the number at the specified index in the array. If index is outside the boundary of the array indexes (0..(array.length() - 1)), an exception is thrown.
return number
extend(array: UInt32Array)
Updates the content of the current array by appending all the contents of array to the end of the array in exact order.
reverse()
Returns a new array containing the elements in the original array in reverse order.
clone()
Returns a new UInt32Array containing all items from the current array. The new array is a shallow copy of the original array.
return UInt32Array
pop()
Removes the last element in the array and returns the value of that item.
return number
to_bytes()
Returns the array as a bytes object
return bytes
to_list()
Returns the elements of the array as a list of numbers
return list
to_string()
Returns a string representation of the array
return string
get_pointer()
Returns the raw uint32 array pointer.
return ptr

class UInt64Array


class UInt64Array represents an array of twos-complement 64-bit unsigned integers in the platform byte order.

@printable @iterable @serializable

class UInt64Array methods


UInt64Array(n: number | list)
  • If n is a number, it creates a new UInt64Array that can hold up to n number of elements, but with all the elements set to 0.
  • If n is a list, it creates a new UInt64Array with its elements set to the values in the list.
constructor
length()
Returns the number of items in the array.
bytes_length()
Returns the length of the array if it were to be converted to bytes.
first()
Returns the first item in the array or nil if the array is empty.
last()
Returns the last item in the array or nil if the array is empty.
append(value: int)
Adds the given value to the end of the array.
get(index: number)
Returns the number at the specified index in the array. If index is outside the boundary of the array indexes (0..(array.length() - 1)), an exception is thrown.
return number
extend(array: UInt64Array)
Updates the content of the current array by appending all the contents of array to the end of the array in exact order.
reverse()
Returns a new array containing the elements in the original array in reverse order.
clone()
Returns a new UInt64Array containing all items from the current array. The new array is a shallow copy of the original array.
return UInt64Array
pop()
Removes the last element in the array and returns the value of that item.
return number
to_bytes()
Returns the array as a bytes object
return bytes
to_list()
Returns the elements of the array as a list of numbers
return list
to_string()
Returns a string representation of the array
return string
get_pointer()
Returns the raw uint64 array pointer.
return ptr

Back to top

Copyright © 2021 Ore Richard Muyiwa. Distributed under the MIT license.