Beispiel #1
0
        private void CopyAndCompress()
        {
            QArrayInner array = new QArrayInner(this as IQArray <T>);

            storage.RemoveReference();
            storage = array;
            start   = 0;
            step    = 1;
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new inner array from an existing one.
 /// </summary>
 /// <param name="other">The existing inner array.</param>
 /// <param name="detach">If true, indicates that the new copy is being detached from the other inner array,
 /// so the reference count of the other array should be decremented.</param>
 private QArrayInner(QArrayInner other, bool detach)
 {
     if (other.storage != null)
     {
         storage = other.storage.Select(ArrayElement).ToList();
     }
     if (detach)
     {
         other.RemoveReference();
     }
 }
Beispiel #3
0
            public QArrayInner SetElement(long index, T value)
            {
                if (storage == null)
                {
                    throw new ArgumentOutOfRangeException();
                }
                QArrayInner newInner = refCount > 1 ? new QArrayInner(this, true) : this;

                newInner.storage[(int)index] = ArrayElement(value);
                return(newInner);
            }
Beispiel #4
0
 /// <summary>
 /// Modifies the element at the given index and returns the QArray.
 /// Note that the modification is an in-place modification!
 /// If the given index is outside the array bounds, it throws
 /// and ArgumentOutOfRangeException.
 /// </summary>
 /// <param name="index">The long index of the element to access</param>
 /// <param name="value">New value of the element</param>
 /// <returns>The element</returns>
 public QArray <T> Modify(long index, T value)
 {
     if (index >= Length)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (storage.UnsafeToSet(ConvertIndex(index)))
     {
         CopyAndCompress();
     }
     storage = storage.SetElement(ConvertIndex(index), value);
     return(this);
 }
Beispiel #5
0
 /// <summary>
 /// Create a copy of an existing array.
 /// </summary>
 public QArray(QArray <T> other)
 {
     if (other == null)
     {
         // Debug.Assert(false, $"Trying to copy a null array");
         storage = new QArrayInner();
     }
     else
     {
         storage = other.storage;
         storage.AddReference();
         start  = other.start;
         step   = other.step;
         Length = other.Length;
     }
 }
Beispiel #6
0
 /// <summary>
 /// Creates an array that contains elements from the collection argument.
 /// </summary>
 /// <param name="collection"> Elements with which the array is initialized.</param>
 public QArray(params T[] collection)
 {
     storage = new QArrayInner(collection);
     Length  = collection.Length;
 }
Beispiel #7
0
 /// <summary>
 /// Creates an array that contains elements from the given argument.
 /// </summary>
 /// <param name="collection"> Elements with which the array is initialized.</param>
 public QArray(IReadOnlyList <T> collection)
 {
     storage = new QArrayInner(collection);
     Length  = collection.Count;
 }
Beispiel #8
0
 /// <summary>
 /// Creates an array that contains elements from the collection argument.
 /// </summary>
 /// <param name="collection"> Elements with which the array is initialized.</param>
 public QArray(IEnumerable <T> collection)
 {
     storage = new QArrayInner(collection);
     Length  = storage.Length;
 }