Share via


VBuffer<T> Struct

Definition

A buffer that supports both dense and sparse representations. This is the representation type for all VectorDataViewType instances. The explicitly defined values of this vector are exposed through GetValues() and, if not dense, GetIndices().

public readonly struct VBuffer<T> : System.Collections.IEnumerable
public readonly struct VBuffer<T>
type VBuffer<'T> = struct
    interface IEnumerable
type VBuffer<'T> = struct
Public Structure VBuffer(Of T)
Implements IEnumerable
Public Structure VBuffer(Of T)

Type Parameters

T

The type of the vector. There are no compile-time restrictions on what this could be, but this code and practically all code that uses VBuffer<T> makes the assumption that an assignment of a value is sufficient to make a completely independent copy of it. So, for example, this means that a buffer of buffers is not possible. But, things like Int32, Single, and ReadOnlyMemory<T>, are totally fine.

Inheritance
VBuffer<T>
Implements

Remarks

This structure is by itself immutable, but to enable buffer editing including re-use of the internal buffers, a mutable variant VBufferEditor<T> can be accessed through VBuffer<T>.

Throughout the code, we make the assumption that a sparse VBuffer<T> is logically equivalent to a dense VBuffer<T> with the default value for T filling in the default values.

Constructors

VBuffer<T>(Int32, Int32, T[], Int32[])

Construct a possibly sparse vector representation.

VBuffer<T>(Int32, T[], Int32[])

Construct a dense representation. The indices array is often unspecified, but if specified it should be considered a buffer to be held on to, to be possibly used.

Fields

Length

The logical length of the buffer.

Properties

IsDense

Gets a value indicating whether every logical element is explicitly represented in the buffer.

Methods

Copy(T[], Int32, VBuffer<T>, Int32)

Copy from a section of a source array to the given destination.

CopyTo(Span<T>, Int32, T)

Copy from this buffer to the given destination span, starting at the specified index. This "densifies."

CopyTo(Span<T>)

Copy from this buffer to the given destination span. This "densifies."

CopyTo(VBuffer<T>, Int32, Int32)

Copy a range of values from this buffer to the given destination.

CopyTo(VBuffer<T>)

Copy from this buffer to the given destination.

CopyToDense(VBuffer<T>)

Copy from this buffer to the given destination, forcing a dense representation.

DenseValues()

Returns an enumerable with Length items, representing the values.

GetEnumerator()

Returns an enumerator that iterates through the values in VBuffer.

GetIndices()

The indices. For a dense representation, this array is not used, and will return the default "empty" span. For a sparse representation it is parallel to that returned from GetValues() and specifies the logical indices for the corresponding values, in increasing order, between 0 inclusive and Length exclusive, corresponding to all explicitly defined values. All values at unspecified indices should be treated as being implicitly defined with the default value of T.

GetItemOrDefault(Int32, T)

Gets the item stored in this structure. In the case of a dense vector this is a simple lookup. In the case of a sparse vector, it will try to find the entry with that index, and set destination to that stored value, or if no such value was found, assign it the default value.

GetItemOrDefault(Int32)

A variant of GetItemOrDefault(Int32, T) that returns the value instead of passing it back using a reference parameter.

GetValues()

The explicitly represented values. When this IsDense, the Length of the returned value will equal Length, and otherwise will have length less than Length.

Items(Boolean)

Returns the joint list of all index/value pairs.

ToString()

Applies to