/// <summary> /// Convert an XArray which uses indices into a contiguous, zero-based array. /// This allows using (fast) Reselect once converted. /// </summary> /// <param name="array">Buffer to use to write contiguous values</param> /// <param name="nulls">Buffer to use for new null array</param> /// <returns>XArray of values written contiguously</returns> public XArray ToContiguous <T>(ref T[] array, ref bool[] nulls) { // If this XArray isn't shifted or indirected, we can use it as-is if (this.Selector.Indices == null && this.Selector.StartIndexInclusive == 0) { return(this); } T[] thisArray = (T[])this.Array; Allocator.AllocateToSize(ref array, this.Count); if (!this.HasNulls) { for (int i = 0; i < this.Count; ++i) { int index = this.Index(i); array[i] = thisArray[index]; } return(XArray.All(array, this.Count)); } else { Allocator.AllocateToSize(ref nulls, this.Count); for (int i = 0; i < this.Count; ++i) { int index = this.Index(i); array[i] = thisArray[index]; nulls[i] = this.NullRows[index]; } return(XArray.All(array, this.Count, nulls)); } }
/// <summary> /// Remap the IsNull array from the source XArray, if any, to a non-indexed array. /// Used when the values in the XAray were converted into an in-order array but IsNull /// from the source needs to be preserved. /// </summary> /// <param name="array">XArray to remap nulls from</param> /// <param name="remapArray">bool[] to use to remap Nulls values, if needed</param> /// <returns>Nulls array to use in returned XArray</returns> public static bool[] RemapNulls(XArray array, ref bool[] remapArray) { // If there were no source nulls, there are none for the output if (!array.HasNulls) { return(null); } // If the source isn't indexed or shifted, the Nulls array may be reused if (array.Selector.Indices == null && array.Selector.StartIndexInclusive == 0) { return(array.NullRows); } // Otherwise, we must remap nulls Allocator.AllocateToSize(ref remapArray, array.Count); bool areAnyNulls = false; for (int i = 0; i < array.Count; ++i) { areAnyNulls |= (remapArray[i] = array.NullRows[array.Index(i)]); } return(areAnyNulls ? remapArray : null); }
public override bool Equals(object obj) { if (!(obj is XArray)) { return(false); } XArray other = (XArray)obj; return(other.Array == this.Array && other.NullRows == this.NullRows && other.Selector == this.Selector); }
/// <summary> /// Replace the values in an XArray and return it with the same selector /// </summary> /// <param name="other">Replacement Array to use</param> /// <returns>XArray with values replaced and Selector the same</returns> public XArray ReplaceValues(XArray other, bool[] nulls) { if (other.Selector.IsSingleValue) { return(new XArray(this) { Array = other.Array, NullRows = nulls, Selector = ArraySelector.Single(this.Count) }); } else { return(new XArray(this) { Array = other.Array, NullRows = nulls }); } }
private XArray(XArray copyFrom) { this.Array = copyFrom.Array; this.NullRows = copyFrom.NullRows; this.Selector = copyFrom.Selector; }
/// <summary> /// Replace the values in an XArray and return it with the same selector /// </summary> /// <param name="other">Replacement Array to use</param> /// <returns>XArray with values replaced and Selector the same</returns> public XArray ReplaceValues(XArray other) { return(ReplaceValues(other, other.NullRows)); }