Exemplo n.º 1
0
 bool overlaps(SortedSet <T> that)
 {
     using (var t = that.GetEnumerator()) {
         if (!t.MoveNext())
         {
             return(false);
         }
         foreach (T item in this)
         {
             int cmp;
             while ((cmp = Comparer.Compare(item, t.Current)) > 0)
             {
                 if (!t.MoveNext())
                 {
                     return(false);
                 }
             }
             if (cmp == 0)
             {
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 2
0
        public bool SetEquals(IEnumerable <T> other)
        {
            CheckArgumentNotNull(other, "other");

            if (Count == 0)
            {
#pragma warning disable 0219
                foreach (T item in other)
                {
                    return(false);
                }
#pragma warning restore 0219
                return(true);
            }

            SortedSet <T> that = nodups(other);

            if (Count != that.Count)
            {
                return(false);
            }

            using (var t = that.GetEnumerator()) {
                foreach (T item in this)
                {
                    if (!t.MoveNext())
                    {
                        throw new SystemException("count wrong somewhere: this longer than that");
                    }
                    if (Comparer.Compare(item, t.Current) != 0)
                    {
                        return(false);
                    }
                }
                if (t.MoveNext())
                {
                    throw new SystemException("count wrong somewhere: this shorter than that");
                }
                return(true);
            }
        }