コード例 #1
0
 /// <summary>
 /// Insere um conjunto de elementos ordenados na colecção.
 /// </summary>
 /// <param name="elementsToInsert">Os elementos a serem inseridos.</param>
 /// <exception cref="ArgumentNullException">Se o conjunto de elementso for nulo.</exception>
 public void AddRange(InsertionSortedCollection <T> elementsToInsert)
 {
     if (elementsToInsert == null)
     {
         throw new ArgumentNullException("elementsToInsert");
     }
     else
     {
         for (int i = 0; i < elementsToInsert.elements.Count; ++i)
         {
             this.Add(elementsToInsert.elements[i]);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Instancia um novo objecto do tipo <see cref="StructureAffector"/>.
        /// </summary>
        /// <param name="affectorStructure">A matriz de afectação.</param>
        /// <exception cref="ArgumentNullException">Se a matriz de afectação for nula.</exception>
        /// <exception cref="ArgumentException">Se a matriz de afectação for vazia.</exception>
        public StructureAffector(ICollection <ICollection <int> > affectorStructure)
        {
            if (affectorStructure == null)
            {
                throw new ArgumentNullException("affectorStructure");
            }

            if (affectorStructure.Count == 0)
            {
                throw new ArgumentException("Parameter collection affectorStructure must have elements to affect.");
            }

            this.affectorMatrix = new int[affectorStructure.Count][];
            int pointer = 0;
            InsertionSortedCollection <int> sorter = new InsertionSortedCollection <int>(Comparer <int> .Default);

            var counter = 0;

            foreach (var item in affectorStructure)
            {
                sorter.Clear();
                foreach (var innerItem in item)
                {
                    if (!sorter.Contains(innerItem))
                    {
                        sorter.Add(innerItem);
                    }
                }

                this.affectorMatrix[pointer++] = sorter.ToArray();
                counter += sorter.Count;
            }

            this.count          = counter;
            this.numberOfPlaces = this.affectorMatrix.Length;
        }
コード例 #3
0
        /// <summary>
        /// Tenta encontrar um valor que se encontre na lista actual mas não se encontre
        /// na lista especificada.
        /// </summary>
        /// <param name="collection">A lista.</param>
        /// <param name="item">O valor.</param>
        /// <returns>
        /// Verdadeiro caso a lista contenha um valor que não se encontre na outra lista
        /// e falso caso contrário.
        /// </returns>
        public bool TryFindValueNotIn(
            InsertionSortedCollection <T> collection,
            out T item)
        {
            item = default(T);
            var elementsEnumerator           = this.elements.GetEnumerator();
            var collectionElementsEnumerator = collection.elements.GetEnumerator();

            if (elementsEnumerator.MoveNext())
            {
                if (collectionElementsEnumerator.MoveNext())
                {
                    var current           = elementsEnumerator.Current;
                    var collectionCurrent = collectionElementsEnumerator.Current;
                    while (true)
                    {
                        if (this.comparer.Compare(collectionCurrent, current) < 0)
                        {
                            if (collectionElementsEnumerator.MoveNext())
                            {
                                collectionCurrent = collectionElementsEnumerator.Current;
                            }
                            else
                            {
                                item = current;
                                return(true);
                            }
                        }
                        else if (this.comparer.Compare(current, collectionCurrent) < 0)
                        {
                            item = current;
                            return(true);
                        }
                        else if (elementsEnumerator.MoveNext())
                        {
                            current = elementsEnumerator.Current;
                            if (collectionElementsEnumerator.MoveNext())
                            {
                                collectionCurrent = collectionElementsEnumerator.Current;
                            }
                            else
                            {
                                item = current;
                                return(true);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    item = elementsEnumerator.Current;
                    return(true);
                }
            }

            return(false);
        }