Пример #1
0
 /// <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)
     });
 }
Пример #2
0
 /// <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)
     });
 }
Пример #3
0
 /// <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)
     });
 }
Пример #4
0
        /// <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))
            });
        }
Пример #5
0
 /// <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
         });
     }
 }
Пример #6
0
        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
            });
        }