Exemplo n.º 1
0
        private void Add(ImmutableArrayInternal <T> array)
        {
            if (array.Length <= 0)
            {
                return;
            }

            array.IncreaseReferences();

            _arrays.Add(array);
            _offsets.Add(_length + array.Length);
            _length += array.Length;
        }
        public ImmutableArrayInternal(int sourceIndex, ImmutableArrayInternal <T> data, int length)
        {
            if ((sourceIndex < 0) || (sourceIndex >= data.Length))
            {
                throw new IndexOutOfRangeException("Index must be between 0 and upper array bound");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data", "Array cannot be null");
            }

            if ((sourceIndex + length) > data.Length)
            {
                throw new ArgumentOutOfRangeException("The sourceIndex and length specified overcome the source ByteArray length");
            }

            _offset = data.Offset + sourceIndex;
            _data   = data.Data;
            _length = length;
            _source = data;
        }
        protected bool EqualsTo(ImmutableArrayInternal <T> array)
        {
            if (_length != array.Length)
            {
                return(false);
            }

            //fast compare
            if (this.GetHashCode() != array.GetHashCode())
            {
                return(false);
            }

            //slow compare
            for (int i = 0; i < _length; i++)
            {
                if (!this[i].Equals(array[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates an immutable array cloning the specified array
 /// </summary>
 /// <param name="data">Array to clone</param>
 /// <param name="length">Length of the data</param>
 /// <param name="sourceIndex">Index of the cloned array where to start cloning</param>
 public ImmutableArray(T[] data, int length, int sourceIndex)
 {
     this.Add(ImmutableArrayInternal <T> .Create(sourceIndex, data, length));
 }
 public ImmutableArrayInternal(ImmutableArrayInternal <T> data, int length)
     : this(0, data, length)
 {
 }
 public ImmutableArrayInternal(ImmutableArrayInternal <T> data)
     : this(data, data.Length)
 {
 }