/// <summary> /// Replace the Selector on this XArray. /// This does not merge with an existing selector. /// This is only safe to use when the selector indices are relative to the real array positions and not any /// indexed positions from this ArraySelector. /// </summary> /// <param name="selector">ArraySelector to *replace* this one with, referring to actual array indices to return.</param> /// <returns>XArray containing the exact rows the selector specified</returns> public XArray Reselect(ArraySelector selector) { return(new XArray(this) { Selector = selector }); }
private ArraySelector(ArraySelector copyFrom) { this.Indices = copyFrom.Indices; this.StartIndexInclusive = copyFrom.StartIndexInclusive; this.EndIndexExclusive = copyFrom.EndIndexExclusive; this.IsSingleValue = copyFrom.IsSingleValue; }
/// <summary> /// Return an XArray matching the rows from this xarray identified in an inner selector. /// If this XArray already uses shifting or indirection, this will look up the real index /// of each row in the innerSelector. /// </summary> /// <param name="innerSelector">ArraySelector referring to the logical [0, Count) rows in this XArray to return</param> /// <param name="remapArray">A buffer to hold remapped indices if they're required</param> /// <returns>XArray containing the remapped rows identified by the innerSelector on the real array</returns> public XArray Select(ArraySelector innerSelector, ref int[] remapArray) { return(new XArray(this) { Selector = this.Selector.Select(innerSelector, ref remapArray) }); }
/// <summary> /// Build an XArray referring to the first element only in an array. /// </summary> /// <param name="array">Array to use first element from</param> /// <returns>XArray wrapping first array value as a Single</returns> public static XArray Single(Array array, int count) { return(new XArray() { Array = array, Selector = ArraySelector.Single(count) }); }
/// <summary> /// Build an XArray with only the value 'false' for the logical row count. /// </summary> /// <param name="count">Number of rows in result XArray</param> /// <returns>XArray with a single value false for everything</returns> public static XArray AllFalse(int count) { return(new XArray() { Array = s_SingleFalse, NullRows = null, Selector = ArraySelector.Single(count) }); }
/// <summary> /// Build an XArray with only the value 'null' for the logical row count. /// </summary> /// <param name="count">Row Count to return 'null' for</param> /// <returns>XArray with a null Array and a single value indicating null for everything</returns> public static XArray Null(Array singleNullValueArray, int count) { return(new XArray() { Array = singleNullValueArray, NullRows = s_SingleTrue, Selector = ArraySelector.Single(count) }); }
/// <summary> /// Build an XArray referring to [0, Count) in the array with the optional given null array. /// </summary> /// <param name="array">Array containing values</param> /// <param name="count">Count of valid Array values</param> /// <param name="nulls">bool[] true for rows which have a null value</param> /// <param name="isSingle">True for IsSingleValue arrays, False otherwise</param> /// <returns>XArray wrapping the array from [0, Count)</returns> public static XArray All(Array array, int count = -1, bool[] nulls = null, bool isSingle = false) { if (array == null) { if (count == 0 || count == -1) { return(XArray.Empty); } throw new ArgumentNullException("array"); } if (count == -1) { count = array.Length; } if (isSingle == false && count > array.Length) { throw new ArgumentOutOfRangeException("length"); } if (isSingle == false && nulls != null && count > nulls.Length) { throw new ArgumentOutOfRangeException("length"); } return(new XArray() { Array = array, NullRows = nulls, Selector = (isSingle ? ArraySelector.Single(count) : ArraySelector.All(count)) }); }
public bool Equals(ArraySelector other) { if (other == null) { return(false); } return(this.Indices == other.Indices && this.StartIndexInclusive == other.StartIndexInclusive && this.EndIndexExclusive == other.EndIndexExclusive); }
public int Next(int desiredCount, CancellationToken cancellationToken) { // Iterate over the cached single page _currentEnumerateSelector = _currentEnumerateSelector.NextPage(_currentPageCount, desiredCount); _currentSelector = _currentEnumerateSelector; for (int i = 0; i < _columns.Length; ++i) { _columns[i].SetSelector(_currentEnumerateSelector); } return(_currentEnumerateSelector.Count); }
/// <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 }); } }
public ArraySelector Select(ArraySelector inner, ref int[] remapArray) { // This selector could refer to a full array [0, Count), a slice [Start, End), or indirection indices. // If this is a single value, return the requested count of copies of it if (this.IsSingleValue) { return(ArraySelector.Single(inner.Count)); } // If this selector is not shifted or indirected, the inner selector can be used as-is if (this.Indices == null && this.StartIndexInclusive == 0) { return(inner); } // If the inner selector specifies just an index and length, we can shift our index and length if (inner.Indices == null) { ArraySelector newSelector = new ArraySelector(this); newSelector.StartIndexInclusive += inner.StartIndexInclusive; newSelector.EndIndexExclusive = newSelector.StartIndexInclusive + inner.Count; return(newSelector); } // Otherwise, we need to remap the indices in the inner array to ones in the real array Allocator.AllocateToSize(ref remapArray, inner.Count); for (int i = 0; i < inner.Count; ++i) { remapArray[i] = Index(inner.Index(i)); } return(new ArraySelector() { StartIndexInclusive = 0, EndIndexExclusive = inner.Count, Indices = remapArray }); }
public void Reset() { // Reset enumeration over the cached single page _currentEnumerateSelector = ArraySelector.All(_currentPageCount).Slice(0, 0); }
private XArray(XArray copyFrom) { this.Array = copyFrom.Array; this.NullRows = copyFrom.NullRows; this.Selector = copyFrom.Selector; }