Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Microsoft.Data.Analysis
/// </summary>
public partial class VBufferDataFrameColumn<T> : DataFrameColumn, IEnumerable<VBuffer<T>>
{

public static int MaxCapacity = ArrayUtility.ArrayMaxSize / Unsafe.SizeOf<VBuffer<T>>();

private readonly List<List<VBuffer<T>>> _vBuffers = new List<List<VBuffer<T>>>(); // To store more than intMax number of vbuffers
Expand Down Expand Up @@ -56,9 +55,7 @@ public VBufferDataFrameColumn(string name, IEnumerable<VBuffer<T>> values) : bas
}
}

private long _nullCount;

public override long NullCount => _nullCount;
public override long NullCount => 0;

protected internal override void Resize(long length)
{
Expand Down Expand Up @@ -94,6 +91,11 @@ private int GetBufferIndexContainingRowIndex(long rowIndex)
}

protected override object GetValue(long rowIndex)
{
return GetTypedValue(rowIndex);
}

protected VBuffer<T> GetTypedValue(long rowIndex)
{
int bufferIndex = GetBufferIndexContainingRowIndex(rowIndex);
return _vBuffers[bufferIndex][(int)(rowIndex % MaxCapacity)];
Expand All @@ -118,30 +120,30 @@ protected override IReadOnlyList<object> GetValues(long startIndex, int length)

protected override void SetValue(long rowIndex, object value)
{
if (value == null || value is VBuffer<T>)
if (value == null)
{
int bufferIndex = GetBufferIndexContainingRowIndex(rowIndex);
int bufferOffset = (int)(rowIndex % MaxCapacity);
var oldValue = _vBuffers[bufferIndex][bufferOffset];
_vBuffers[bufferIndex][bufferOffset] = (VBuffer<T>)value;
if (!oldValue.Equals((VBuffer<T>)value))
{
if (value == null)
_nullCount++;
if (oldValue.Length == 0 && _nullCount > 0)
_nullCount--;
}
throw new NotSupportedException("Null values are not supported by VBufferDataFrameColumn");
}
else if (value is VBuffer<T> vbuffer)
{
SetTypedValue(rowIndex, vbuffer);
}
else
{
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(VBuffer<T>)), nameof(value));
}
}

protected void SetTypedValue(long rowIndex, VBuffer<T> value)
{
int bufferIndex = GetBufferIndexContainingRowIndex(rowIndex);
_vBuffers[bufferIndex][(int)(rowIndex % MaxCapacity)] = value;
}

public new VBuffer<T> this[long rowIndex]
{
get => (VBuffer<T>)GetValue(rowIndex);
set => SetValue(rowIndex, value);
get => GetTypedValue(rowIndex);
set => SetTypedValue(rowIndex, value);
}

/// <summary>
Expand Down