Show / Hide Table of Contents

Class SparseVector<T>

A vector that uses sparse storage methods with doubly-linked elements.

Inheritance
object
SparseVector<T>
Implements
ISparseVector<T>
IVector<T>
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: SpiceSharp.Algebra
Assembly: SpiceSharp.dll
Syntax
public class SparseVector<T> : ISparseVector<T>, IVector<T>
Type Parameters
Name Description
T

The base value type.

Remarks

The element at index 0 is considered a "trashcan" element under the hood, consistent to SparseMatrix<T>. This doesn't really make a difference for indexing the vector though.

This vector automatically expands size if necessary.

Constructors

SparseVector()

Initializes a new instance of the SparseVector<T> class.

Declaration
public SparseVector()

SparseVector(int)

Initializes a new instance of the SparseVector<T> class.

Declaration
public SparseVector(int length)
Parameters
Type Name Description
int length

The length of the vector.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if length is negative.

Properties

ElementCount

Gets the number of elements in the vector.

Declaration
public int ElementCount { get; }
Property Value
Type Description
int

The element count.

this[int]

Gets or sets the value at the specified index.

Declaration
public T this[int index] { get; set; }
Parameters
Type Name Description
int index

The index.

Property Value
Type Description
T

The value.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if index is negative.

Length

Gets the length of the vector.

Declaration
public int Length { get; }
Property Value
Type Description
int

The length.

Methods

Clear()

Clears all elements in the vector. The size of the vector becomes 0.

Declaration
public void Clear()

CopyTo(IVector<T>)

Copies the contents of the vector to another one.

Declaration
public void CopyTo(IVector<T> target)
Parameters
Type Name Description
IVector<T> target

The target vector.

Exceptions
Type Condition
ArgumentNullException

Thrown if target is null.

ArgumentException

Thrown if target does not have the same length as this vector.

FindElement(int)

Finds a vector element at the specified index.

Declaration
public Element<T> FindElement(int index)
Parameters
Type Name Description
int index

The index.

Returns
Type Description
Element<T>

The vector element; otherwise null.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if index is negative.

GetElement(int)

Gets a vector element at the specified index. If it doesn't exist, a new one is created.

Declaration
public Element<T> GetElement(int index)
Parameters
Type Name Description
int index

The index.

Returns
Type Description
Element<T>

The vector element.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if index is negative.

GetFirstInVector()

Gets the first ISparseVectorElement<T> in the vector.

Declaration
public ISparseVectorElement<T> GetFirstInVector()
Returns
Type Description
ISparseVectorElement<T>

The first element in the vector.

GetLastInVector()

Gets the last ISparseVectorElement<T> in the vector.

Declaration
public ISparseVectorElement<T> GetLastInVector()
Returns
Type Description
ISparseVectorElement<T>

The last element in the vector.

RemoveElement(int)

Removes a vector element at the specified index.

Declaration
public bool RemoveElement(int index)
Parameters
Type Name Description
int index

The index.

Returns
Type Description
bool

true if the element was removed; otherwise, false.

Reset()

Resets all elements in the vector to their default value.

Declaration
public void Reset()

SwapElements(int, int)

Swaps two elements in the vector.

Declaration
public void SwapElements(int index1, int index2)
Parameters
Type Name Description
int index1

The first index.

int index2

The second index.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if index1 or index2 is negative.

ToString()

Returns a string that represents this instance.

Declaration
public override string ToString()
Returns
Type Description
string

A string that represents this instance.

Overrides
object.ToString()

Implements

ISparseVector<T>
IVector<T>

Extension Methods

Utility.ThrowIfNull<T>(T, string)

See Also

ISparseVector<T>
In this article
Back to top Generated by DocFX