Click or drag to resize

Integer Array

Shared implementation of the integer array. This class implements interfaces SharedDataT<Int32>, ICloneable, IFormattable, IList<Int32>, IList

This topic contains the following sections:

Create

Constructor

Description

Performance

set size

Creates new instance of IntegerArray.

methodIntegerArray(Int32)

default size

Creates new instance of IntegerArray with default zero size.

methodIntegerArray

set size and buffer capasity

Creates new instance of IntegerArray.

methodIntegerArray(Int32, Int32)

copy from array

Creates IntegerArray with elements from specified array.

methodIntegerArray(Int32)

There are also static methods for quick creation of IntegerArray.

Method

Description

Performance

random permute

Creates the IntegerArray of given size which is random permute of numbers from 0 to size - 1.

StaticRandom(Int32)

sample of a distribution

Creates the IntegerArray of given size with elements that are sampled from the specified distribution.

StaticRandom(Int32, DUDistribution)

An IntegerArray instance has a set of properties:

Property

Description

Performance

length

Number of elements in the collection.

PropertyLength

a certain element

Returns certain element of the array by its index.

PropertyItemInt32

is fixed size

Returns true if and only if collection has fixed size.

PropertyIsFixedSize

is read only

Returns true if and only if collection is read only.

PropertyIsReadOnly

Manage and Access

Method

Description

Performance

resize

Resize container to specified size. New Length and internal capacity will be set to specified value. Missing values will be filled with zeros.

methodResize(Int32)

sort

Sort elements of the collection.

methodSort

add

Adds new element to IntegerArray.

methodAdd(Int32)

Adds new element to IntegerArray and returns the index in which the element is placed.

methodAdd(Object)

insert

Insert element on position. All elements starting from index to collection size will be shifted to the right.

methodInsert(Int32, Int32)

Insert element on position. All elements starting from index to collection size will be shifted to the right.

methodInsert(Int32, Object)

remove

Remove element with smallest index equal to specified. All element with indices greater than removed will be shifted left.

methodRemove(Object)

methodRemove(Int32)

Remove element stored on position. All element with indices greater than removed will be shifted left.

methodRemoveAt(Int32)

clear

Drop all elements from IntegerArray.

methodClear

contains

Returns true if and only if there is element equal to value in IntegerArray.

methodContains(Object)

methodContains(Int32)

index of

Returns smallest index of specified element in IntegerArray. If there is no such element in IntegerArray returns -1.

methodIndexOf(Object)

methodIndexOf(Int32)

get enumerator

Returns an enumerator that iterates through a collection.

methodGetEnumerator

Copy and Convert

Method

Description

Performance

copy to array

Copy data from integer array to native c# array.

methodToArray

Copy starting at a particular array index:

methodCopyTo(Array, Int32)

methodCopyTo(Int32, Int32)

clone

Supports cloning, which creates a new instance of a class with the same value as an existing instance.

methodClone

to string

Formats the value of the current instance using the specified format.

methodToString

methodToString(String, IFormatProvider)

Save and Load

Method

Description

Performance

save

Saves IntegerArray to CSV file at the specified path.

methodSave(String)

load

Loads IntegerArray from CSV file at the specified path.

methodLoad(String)

Code Sample

The following example demonstrates the Integer Array usage:

C#
 1using System;
 2using FinMath.DataStructures;
 3using FinMath.LinearAlgebra;
 4
 5namespace FinMath.Samples
 6{
 7    class IntegerArraySample
 8    {
 9        static void Main()
10        {
11            // Input parameters.
12            const Int32 rowsCount = 7;
13            const Int32 columnsCount = 5;
14
15            // Generating input.
16            Matrix matrix = Matrix.Random(rowsCount, columnsCount);
17            Console.WriteLine("Input matrix:");
18            Console.WriteLine(matrix.ToString("0.000"));
19            // Generating random permutation of numbers from 0 to rowsCount - 1.
20            IntegerArray rowsPermutation = IntegerArray.Random(rowsCount);
21            Console.WriteLine("Rows permutation:");
22            Console.WriteLine(rowsPermutation);
23            // Generating random permutation of numbers from 0 to columnsCount - 1.
24            IntegerArray columnsPermutationTemp = IntegerArray.Random(columnsCount);
25            IntegerArray columnsPermutation = new IntegerArray();
26
27            // IntegerArray can be used just like C# List<Int32> collection.
28            // You can store elements into it using Add(Int32) method, and it will expand itself 
29            // if there is no enough memory to complete operation.
30            for (Int32 i = 0; i < columnsCount; ++i)
31                columnsPermutation.Add(columnsPermutationTemp[i]);
32
33            Console.WriteLine("Columns permutation:");
34            Console.WriteLine(columnsPermutation);
35
36            // Apply permutations:
37            matrix.PermuteRows(rowsPermutation);
38            matrix.PermuteColumns(columnsPermutation);
39
40            // Output results:
41            Console.WriteLine();
42            Console.WriteLine("Matrix after permutations:");
43            Console.WriteLine(matrix.ToString("0.000"));
44        }
45    }
46}