Ejemplo n.º 1
0
        /// <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 the list.</param>
        /// <returns>return true if this list Changed as a result of the call.</returns>
        public bool RemoveAll(IntList c)
        {
            bool rval = false;

            for (int j = 0; j < c._limit; j++)
            {
                if (RemoveValue(c._array[j]))
                {
                    rval = true;
                }
            }
            return(rval);
        }
Ejemplo n.º 2
0
 /// <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(IntList 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);
 }
Ejemplo n.º 3
0
        /// <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(IntList 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);
        }
Ejemplo n.º 4
0
        /// <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(IntList c)
        {
            bool rval = false;

            for (int j = 0; j < _limit;)
            {
                if (!c.Contains(_array[j]))
                {
                    Remove(j);
                    rval = true;
                }
                else
                {
                    j++;
                }
            }
            return(rval);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Compares the specified object with this list for Equality.
        /// Returns true if and only if the specified object is also a
        /// list, both lists have the same size, and all corresponding
        /// pairs of elements in the two lists are Equal.  (Two elements e1
        /// and e2 are equal if e1 == e2.)  In other words, two lists are
        /// defined to be equal if they contain the same elements in the
        /// same order.  This defInition ensures that the Equals method
        /// works properly across different implementations of the List
        /// interface.
        /// </summary>
        /// <param name="o">the object to be Compared for Equality with this list.</param>
        /// <returns>return true if the specified object is equal to this list.</returns>
        public override bool Equals(Object o)
        {
            bool rval = this == o;

            if (!rval && (o != null) && (o.GetType() == this.GetType()))
            {
                IntList other = (IntList)o;

                if (other._limit == _limit)
                {
                    // assume match
                    rval = true;
                    for (int j = 0; rval && (j < _limit); j++)
                    {
                        rval = _array[j] == other._array[j];
                    }
                }
            }
            return(rval);
        }
Ejemplo n.º 6
0
        /// <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>
        public bool AddAll(int index, IntList 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);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// create a copy of an existing IntList
 /// </summary>
 /// <param name="list">the existing IntList</param>
 public IntList(IntList list)
     : this(list._array.Length)
 {
     Array.Copy(list._array, 0, _array, 0, _array.Length);
     _limit = list._limit;
 }