array: Generic and Dynamic Arrays
(require array) | package: array |
The array module provides a generic interface for the array, a data structure that uses compact, constant-time, natural-number indexing and updating. Racket has many built-in types which act as either homogeneous (all elements have the same type) or heterogeneous (elements can have different types) arrays, such as the vector, byte string, string, flvector, and others. This module also provides an implementation of the dynamic array, an array which grows exponentially, allowing for an amortized O(1) append operation.
1 Generic Arrays
syntax
procedure
(array-set! array idx val) → void?
array : array? idx : exact-nonnegative-integer? val : any/c
procedure
(array-ref array idx) → any/c
array : array? idx : exact-nonnegative-integer?
procedure
(array-length array) → exact-nonnegative-integer?
array : array?
procedure
(array-alloc array len) → array?
array : array? len : exact-nonnegative-integer?
procedure
(array-copy! dest dest-start array [ array-start array-end]) → void? dest : array? dest-start : exact-nonnegative-integer? array : array? array-start : exact-nonnegative-integer? = 0 array-end : exact-nonnegative-integer? = (array-length array)
procedure
(array-empty? array) → boolean?
array : array?
procedure
(array-first array) → any/c
array : array?
procedure
(array-last array) → any/c
array : array?
procedure
(array->list array) → list?
array : array?
procedure
(array->vector array) → vector?
array : array?
2 Dynamic Arrays
(require array/dynamic) | package: array |
struct
(struct dynamic-array (buffer length))
buffer : array? length : exact-nonnegative-integer?
procedure
(dynamic-array? obj) → boolean?
obj : any/c
procedure
arr : array? len : exact-nonnegative-integer? = (array-length arr)
procedure
(dynamic-array-buffer array) → array?
array : dynamic-array?
procedure
(dynamic-array-length array) → exact-nonnegative-integer?
array : dynamic-array?
procedure
(dynamic-array-capacity array) → exact-nonnegative-integer?
array : dynamic-array?
procedure
(dynamic-array-ensure-capacity array min-cap) → void? array : dynamic-array? min-cap : exact-nonnegative-integer?
procedure
(dynamic-array-append! array new-values) → void?
array : dynamic-array? new-values : array?
procedure
→ exact-nonnegative-integer? array : dynamic-array? new-value : any/c
procedure
(dynamic-array-contents array) → array?
array : dynamic-array?