/// <summary> /// create a copy of an existing shortList /// </summary> /// <param name="list">the existing shortList</param> public ShortList(ShortList list) : this(list._array.Length) { Array.Copy(list._array, 0, _array, 0, _array.Length); _limit = list._limit; }
/// <summary> /// Retains only the elements in this list that are Contained in /// the specified collection. In other words, Removes from this /// list all the elements that are not Contained in the specified /// collection. /// </summary> /// <param name="c">collection that defines which elements this Set will retain.</param> /// <returns>return true if this list Changed as a result of the call.</returns> public bool RetainAll(ShortList c) { bool rval = false; for (int j = 0; j < _limit; ) { if (!c.Contains(_array[j])) { Remove(j); rval = true; } else { j++; } } return rval; }
/// <summary> /// Removes from this list all the elements that are Contained in the specified collection /// </summary> /// <param name="c">collection that defines which elements will be removed from this list.</param> /// <returns>return true if this list Changed as a result of the call.</returns> public bool RemoveAll(ShortList c) { bool rval = false; for (int j = 0; j < c._limit; j++) { if (RemoveValue(c._array[j])) { rval = true; } } return rval; }
/// <summary> /// Returns true if this list Contains all of the elements of the specified collection. /// </summary> /// <param name="c">collection to be Checked for Containment in this list.</param> /// <returns>return true if this list Contains all of the elements of the specified collection.</returns> public bool ContainsAll(ShortList c) { bool rval = true; if (this != c) { for (int j = 0; rval && (j < c._limit); j++) { if (!Contains(c._array[j])) { rval = false; } } } return rval; }
/// <summary> /// Inserts all of the elements in the specified collection into /// this list at the specified position. Shifts the element /// currently at that position (if any) and any subsequent elements /// to the right (increases their indices). The new elements will /// appear in this list in the order that they are returned by the /// specified collection's iterator. The behavior of this /// operation is unspecified if the specified collection is /// modified while the operation is in progress. (Note that this /// will occur if the specified collection is this list, and it's /// nonempty.) /// </summary> /// <param name="index">index at which to insert first element from the specified collection.</param> /// <param name="c">elements to be inserted into this list.</param> /// <returns>return true if this list Changed as a result of the call.</returns> /// <exception cref="IndexOutOfRangeException"> if the index is out of range (index < 0 || index > size())</exception> public bool AddAll(int index, ShortList c) { if (index > _limit) { throw new IndexOutOfRangeException(); } if (c._limit != 0) { if ((_limit + c._limit) > _array.Length) { GrowArray(_limit + c._limit); } // make a hole Array.Copy(_array, index, _array, index + c._limit, _limit - index); // fill it in Array.Copy(c._array, 0, _array, index, c._limit); _limit += c._limit; } return true; }
/// <summary> /// Appends all of the elements in the specified collection to the /// end of this list, in the order that they are returned by the /// specified collection's iterator. The behavior of this /// operation is unspecified if the specified collection is /// modified while the operation is in progress. (Note that this /// will occur if the specified collection is this list, and it's /// nonempty.) /// </summary> /// <param name="c">collection whose elements are to be Added to this list.</param> /// <returns>return true if this list Changed as a result of the call.</returns> public bool AddAll(ShortList c) { if (c._limit != 0) { if ((_limit + c._limit) > _array.Length) { GrowArray(_limit + c._limit); } Array.Copy(c._array, 0, _array, _limit, c._limit); _limit += c._limit; } return true; }