示例#1
0
        private static void Comparer_VerifyWhereAll <T>(T[] left, T[] right, T value) where T : IComparable <T>
        {
            // Try operations between array and single value
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.Single(new T[1] {
                value
            }, left.Length), CompareOperator.Equal);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.Single(new T[1] {
                value
            }, left.Length), CompareOperator.NotEqual);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.Single(new T[1] {
                value
            }, left.Length), CompareOperator.GreaterThan);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.Single(new T[1] {
                value
            }, left.Length), CompareOperator.GreaterThanOrEqual);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.Single(new T[1] {
                value
            }, left.Length), CompareOperator.LessThan);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.Single(new T[1] {
                value
            }, left.Length), CompareOperator.LessThanOrEqual);

            // Try operations between two arrays
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.All(right, right.Length), CompareOperator.Equal);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.All(right, right.Length), CompareOperator.NotEqual);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.All(right, right.Length), CompareOperator.GreaterThan);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.All(right, right.Length), CompareOperator.GreaterThanOrEqual);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.All(right, right.Length), CompareOperator.LessThan);
            Comparer_VerifyWhere <T>(XArray.All(left, left.Length), XArray.All(right, right.Length), CompareOperator.LessThanOrEqual);
        }
示例#2
0
 private XArray Get(int count)
 {
     if (IsNull)
     {
         return(XArray.Null(_array, count));
     }
     return(XArray.Single(_array, count));
 }
示例#3
0
        // Return an IsSingleElement array with just the first value of the xarray, but the same count
        public static XArray First(XArray values)
        {
            Array modifiedArray = null;

            Allocator.AllocateToSize(ref modifiedArray, 1, values.Array.GetType().GetElementType());
            modifiedArray.SetValue(values.Array.GetValue(values.Index(0)), 0);

            return(XArray.Single(modifiedArray, values.Count));
        }
示例#4
0
        public ConstantColumn(IXTable source, object value, Type type, bool wasUnwrappedLiteral = false)
        {
            Source = source;

            Allocator.AllocateToSize(ref _array, 1, type);
            _array.SetValue(value, 0);

            IsNull  = (value == null || value.Equals("null"));
            _xArray = (IsNull ? XArray.Null(_array, 1) : XArray.Single(_array, 1));

            WasUnwrappedLiteral = wasUnwrappedLiteral;
            ColumnDetails       = new ColumnDetails(string.Empty, type);
        }
        public static bool TryConvertSingle(object value, Type targetType, out object result)
        {
            // Nulls are always converted to null
            if (value == null)
            {
                result = null;
                return(true);
            }

            // If the type is already right, just return it
            Type sourceType = value.GetType();

            if (sourceType.Equals(targetType))
            {
                result = value;
                return(true);
            }

            // Get the converter for the desired type combination
            Func <XArray, XArray> converter = GetConverter(sourceType, targetType);

            Array array = null;

            Allocator.AllocateToSize(ref array, 1, sourceType);
            array.SetValue(value, 0);

            XArray resultxarray = converter(XArray.Single(array, 1));

            // Verify the result was not null unless the input was "" or 'null'
            if (resultxarray.HasNulls && resultxarray.NullRows[resultxarray.Index(0)])
            {
                result = null;

                string stringValue = value.ToString();
                if (stringValue != "" || String.Compare(stringValue, "null", true) == 0)
                {
                    return(true);
                }
                return(false);
            }

            result = resultxarray.Array.GetValue(resultxarray.Index(0));
            return(true);
        }
        private XArray Convert(XArray xarray)
        {
            // If a single value was returned, only convert it
            if (xarray.Selector.IsSingleValue)
            {
                Allocator.AllocateToSize(ref _buffer, 1);
                _buffer[0] = _function(((T[])xarray.Array)[0]);
                return(XArray.Single(_buffer, xarray.Count));
            }

            // Allocate for results
            Allocator.AllocateToSize(ref _buffer, xarray.Count);

            // Convert each non-null value
            T[] array = (T[])xarray.Array;
            for (int i = 0; i < xarray.Count; ++i)
            {
                int  index     = xarray.Index(i);
                bool rowIsNull = (xarray.HasNulls && xarray.NullRows[index]);
                _buffer[i] = (rowIsNull ? default(U) : _function(array[index]));
            }

            return(XArray.All(_buffer, xarray.Count, XArray.RemapNulls(xarray, ref _isNull)));
        }
 private XArray Get()
 {
     return(_isNull ? XArray.Null(_array, _source.CurrentRowCount) : XArray.Single(_array, _source.CurrentRowCount));
 }
示例#8
0
        public XArray Add(XArray left, XArray right)
        {
            long[] leftArray  = (long[])left.Array;
            long[] rightArray = (long[])right.Array;

            int count = left.Count;

            if (right.Count != count)
            {
                throw new InvalidOperationException("Computations must get the same number of rows from each argument.");
            }

            bool areAnyNull = false;

            // Allocate for results
            Allocator.AllocateToSize(ref _buffer, count);
            Allocator.AllocateToSize(ref _isNull, count);

            // Check how the XArrays are configured and run the fastest loop possible for the configuration.
            if (left.HasNulls || right.HasNulls)
            {
                for (int i = 0; i < count; ++i)
                {
                    int index1 = left.Index(i);
                    int index2 = right.Index(i);

                    bool rowIsNull = (left.HasNulls && left.NullRows[index1]) || (right.HasNulls && right.NullRows[index2]);
                    areAnyNull |= rowIsNull;

                    _isNull[i] = rowIsNull;
                    _buffer[i] = leftArray[index1] + rightArray[index2];
                }
            }
            else if (left.Selector.Indices != null || right.Selector.Indices != null)
            {
                for (int i = 0; i < left.Count; ++i)
                {
                    _buffer[i] = leftArray[left.Index(i)] + rightArray[right.Index(i)];
                }
            }
            else if (!right.Selector.IsSingleValue && !left.Selector.IsSingleValue)
            {
                int leftStart  = left.Selector.StartIndexInclusive;
                int rightStart = right.Selector.StartIndexInclusive;
                for (int i = 0; i < count; ++i)
                {
                    _buffer[i] = leftArray[i + leftStart] + rightArray[i + rightStart];
                }
            }
            else if (!left.Selector.IsSingleValue)
            {
                int  leftStart  = left.Selector.StartIndexInclusive;
                long rightValue = rightArray[right.Selector.StartIndexInclusive];

                for (int i = 0; i < count; ++i)
                {
                    _buffer[i] = leftArray[i + leftStart] + rightValue;
                }
            }
            else if (!right.Selector.IsSingleValue)
            {
                long leftValue  = leftArray[left.Selector.StartIndexInclusive];
                int  rightStart = right.Selector.StartIndexInclusive;

                for (int i = 0; i < count; ++i)
                {
                    _buffer[i] = leftValue + rightArray[i + rightStart];
                }
            }
            else
            {
                _buffer[0] = leftArray[left.Selector.StartIndexInclusive] + rightArray[right.Selector.StartIndexInclusive];
                return(XArray.Single(_buffer, count));
            }

            return(XArray.All(_buffer, count, (areAnyNull ? _isNull : null)));
        }