Пример #1
0
        /// <summary>
        ///
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public ListBounded <T> SubsetNotIn(ListBounded <T> other, ref T[] scratchBuffer)
        {
            if (scratchBuffer == null || scratchBuffer.Length < other.MaxLength)
            {
                scratchBuffer = new T[other.MaxLength];
            }

            int countThis  = Count;
            int countOther = other.Count;

            // Make a copy of the other buffer and sort the copy
            Array.Copy(other.array, scratchBuffer, countOther);
            Array.Sort(scratchBuffer, 0, countOther);

            ListBounded <T> ret = new ListBounded <T>(Count);

            for (int i = 0; i < countThis; i++)
            {
                T item = this[i];

                // Search other array for this item, and add to our return list if not found
                if (Array.BinarySearch(scratchBuffer, 0, countOther, item) < 0)
                {
                    ret.Add(item);
                }
            }
            return(ret);
        }
Пример #2
0
        /// <summary>
        ///
        ///
        /// NOTE: this is destructive because it sorts the array sunderlying both ListBounded.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public ListBounded <T> SubsetNotInOLD(ListBounded <T> other)
        {
            Array.Sort(array, 0, Count);
            Array.Sort(other.array, 0, other.Count);

            int len2 = other.Count;
            int pos2 = 0;

            ListBounded <T> ret = new ListBounded <T>(Count);

            for (int i = 0; i < Count; i++)
            {
                T item = this[i];

                while (pos2 < len2 && other[pos2].CompareTo(item) == -1)
                {
                    pos2++;
                }

                if (pos2 == len2 || other[pos2].CompareTo(item) == 1)
                {
                    ret.Add(item);
                }
            }
            return(ret);
        }
Пример #3
0
 internal Enumerator(ListBounded <T> list)
 {
     this.list = list;
     index     = 0;
     version   = list.version;
     current   = default(T);
 }
Пример #4
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Returns a new ListBounded which represents the union of items (including possible duplicates).
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public ListBounded <T> UnionWith(ListBounded <T> other)
        {
            ListBounded <T> ret = new ListBounded <T>(Count + other.Count);

            Array.Copy(array, ret.array, Count);
            Array.Copy(other.array, 0, ret.array, Count, other.Count);

            return(ret);
        }
Пример #5
0
        /// <summary>
        /// Returns a new ListBounded which represents the (sorted) union of items (excluding duplicates).
        ///
        /// NOTE: this is destructive because it sorts the array sunderlying both ListBounded.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public ListBounded <T> UnionDistinctWith(ListBounded <T> other)
        {
            Array.Sort(array, 0, Count);
            Array.Sort(other.array, 0, other.Count);

            int len1 = this.Count;
            int len2 = other.Count;

            int pos1 = 0;
            int pos2 = 0;

            ListBounded <T> ret = new ListBounded <T>(len1 + len2);

            while (pos1 < len1 || pos2 < len2)
            {
                if (pos1 == len1)
                {
                    ret.Add(other[pos2++]);
                }
                else if (pos2 == len2)
                {
                    ret.Add(this[pos1++]);
                }
                else
                {
                    T try1 = this[pos1];
                    T try2 = other[pos2];

                    int compareResult = try1.CompareTo(try2);
                    if (compareResult == 0)
                    {
                        ret.Add(try1);
                        pos1++;
                        pos2++;
                    }
                    else if (compareResult == -1)
                    {
                        ret.Add(try1);
                        pos1++;
                    }
                    else if (compareResult == 1)
                    {
                        ret.Add(try2);
                        pos2++;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
            }
            return(ret);
        }
Пример #6
0
            public bool MoveNext()
            {
                ListBounded <T> localArray = list;

                if (version == localArray.version && ((uint)index < (uint)localArray.length))
                {
                    current = localArray.array[index];
                    index++;
                    return(true);
                }
                return(MoveNextRare());
            }
Пример #7
0
 public ListBounded(ListBounded <T> other, StorageMode storageMode = StorageMode.AllocatedArray)
 {
     DoCreate(other.Count, storageMode);
     length = other.Count;
     Array.Copy(other.array, array, other.Count);
 }
Пример #8
0
 public void Set(ListBounded <T> items)
 {
     length = items.Count;
     Array.Copy(items.array, array, items.Count);
     version++;
 }
Пример #9
0
 /// <summary>
 /// Adds a specified ListBounded of items to the array
 /// </summary>
 /// <param name="t"></param>
 public void Add(ListBounded <T> t, int maxElements = int.MaxValue)
 {
     version++;
     Array.Copy(t.array, 0, array, length, System.Math.Min(t.Count, maxElements));
     length += t.Count;
 }