/// <summary> /// This methods allocates a mutable array and copies all the colletion elements to it /// </summary> /// <param name="collection">Collection to copy elements from</param> /// <returns>Array</returns> private static T[] AllocInternalArray(ICollection <T> collection) { T[] ret = ImmutableArrayInternal <T> .AllocInternalArray(collection.Count); collection.CopyTo(ret, 0); return(ret); }
/// <summary> /// Gets a portion of the array starting from the specified index for the specified length /// </summary> /// <param name="sourceIndex">Index to start from</param> /// <param name="length">Length of the portion</param> /// <returns>An immutable array that is a portion of this array</returns> public ImmutableArray <T> SubArray(int sourceIndex, int length) { if ((this.Count == sourceIndex) && (length == 0)) { return(Empty); } List <ImmutableArrayInternal <T> > ret = new List <ImmutableArrayInternal <T> >(); int i = this.GetArrayIndexAt(ref sourceIndex); if ((sourceIndex + length) > this.Count) { throw new ArgumentOutOfRangeException("The sourceIndex and length specified overcome the array length"); } ImmutableArrayInternal <T> array = _arrays[i]; array = new ImmutableArrayInternal <T>(sourceIndex, array, array.Length < length ? array.Length : length); length -= array.Length; ret.Add(array); for (i += 1; (length > 0) && (i < _arrays.Count); i++) { array = _arrays[i]; if (array.Length > length) //if only partial create a subarray { array = array.SubArrayInternal(0, length); } ret.Add(array); length -= array.Length; } return(new ImmutableArray <T>(ret.ToArray())); }
private void Add(ImmutableArrayInternal <T> array) { if (array.Length <= 0) { return; } _arrays.Add(array); _offsets.Add(this.Count + array.Length); _length += array.Length; }
/// <summary> /// This method allocates a copy of the specified array /// </summary> /// <param name="sourceIndex">Index to start the copy</param> /// <param name="data">Array of data to be copied</param> /// <param name="length">Length od data to topy</param> /// <returns>A partial/complete clone of the specified array</returns> private static T[] AllocInternalArray(int sourceIndex, T[] data, int length) { if (length == 0) { return(EmptyArray); } T[] ret = ImmutableArrayInternal <T> .AllocInternalArray(length); Array.Copy(data, sourceIndex, ret, 0, length); return(ret); }
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"); } this.Offset = data.Offset + sourceIndex; this.Data = data.Data; this.Length = length; }
public ImmutableArrayInternal(int sourceIndex, T[] data, int length) { if (sourceIndex < 0) { throw new IndexOutOfRangeException("Index cannot be less than zero"); } 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 = 0; _data = ImmutableArrayInternal <T> .AllocInternalArray(sourceIndex, data, length); _length = length; }
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); }
public ImmutableArrayInternal(ImmutableArrayInternal <T> data, int length) : this(0, data, length) { }
public ImmutableArrayInternal(ImmutableArrayInternal <T> data) : this(data, data.Length) { }