"FixedArray" (Data Structure)

"FixedArray"

represents an array of fixed length where the elements are general expressions.

Details

  • A fixed-length array is useful for efficient element extraction and updating:
  • CreateDataStructure[ "FixedArray",n]create a new "FixedArray" with n elements
    CreateDataStructure[ "FixedArray",x,n]create a new "FixedArray" of length n initialized to x
    CreateDataStructure[ "FixedArray",elems]create a new "FixedArray" containing elems
    Typed[x,"FixedArray"]give x the type "FixedArray"
  • For a data structure of type "FixedArray", the following operations can be used:
  • ds["Copy"]return a copy of dstime: O(n)
    ds["Elements"]return a list of the elements of dstime: O(n)
    ds["EmptyQ"]True, if ds has no elementstime: O(1)
    ds["Fold",fun,init]apply fun to the elements of ds, starting with init, accumulating a resulttime: O(n)
    ds["Length"]number of elements stored in dstime: O(1)
    ds["Part",i]give the i^(th) part of dstime: O(1)
    ds["SetPart",i,elem]update the i^(th) part of dstime: O(1)
    ds["SwapPart",i,j]swap the i^(th) and j^(th) parts of dstime: O(1)
    ds["Visualization"]return a visualization of dstime: O(n)
  • The following functions are also supported:
  • dsi===dsjTrue, if dsi equals dsj
    ds["Part",i]=valset i^(th) element of ds to val
    FullForm[ds]full form of ds
    Information[ds]information about ds
    InputForm[ds]input form of ds
    Normal[ds]convert ds to a normal expression

Examples

open allclose all

Basic Examples  (3)

A new "FixedArray" can be created with CreateDataStructure:

Return the length:

Return an expression version of ds. The elements are initialized to Null:

Change an element:

The element has updated:

The expression version of ds:

It is fast to update elements:

A visualization of the data structure can be generated:

Sum all the elements:

An initial value can be given:

Scope  (1)

Information  (1)

A new "FixedArray" can be created with CreateDataStructure:

Information about the data structure ds:

Properties & Relations  (1)

"DynamicArray"  (1)

Many algorithms that work for "DynamicArray" also work for "FixedArray".

Possible Issues  (2)

The number of elements of the array needs to be specified as a positive integer:

You cannot set parts of the array that do not exist:

Interactive Examples  (1)

Compute and store individual plots in a data structure and use Manipulate to interactively display them:

Neat Examples  (2)

Fibonacci  (1)

Compute the first 16 elements of the Fibonacci sequence:

Set the first two elements to 1, then compute the remaining elements:

Display the result:

Histogram  (1)

A function that computes a histogram of the different color values of an image:

Run the function on the pixels of an image:

Display the result: