コード例 #1
0
        public HSetInternal <T> Subtract(HSetInternal <T> rhs)
        {
            var self = this;

            foreach (var item in rhs)
            {
                self = self.Remove(item);
            }
            return(self);
        }
コード例 #2
0
        public HSetInternal <T> Append(HSetInternal <T> rhs)
        {
            var self = this;

            foreach (var item in rhs)
            {
                if (!self.Contains(item))
                {
                    self = self.Add(item);
                }
            }
            return(self);
        }
コード例 #3
0
        public bool IsSubsetOf(IEnumerable <T> other)
        {
            if (IsEmpty)
            {
                return(true);
            }

            var otherSet = new HSetInternal <T>(other);
            int matches  = 0;

            foreach (var item in otherSet)
            {
                if (Contains(item))
                {
                    matches++;
                }
            }
            return(matches == Count);
        }
コード例 #4
0
        internal HSetInternal(IEnumerable <T> items, bool checkUniqueness = false)
        {
            var set = new HSetInternal <T>();

            if (checkUniqueness)
            {
                foreach (var item in items)
                {
                    set = set.TryAdd(item);
                }
            }
            else
            {
                foreach (var item in items)
                {
                    set = set.Add(item);
                }
            }
        }
コード例 #5
0
        public bool Equals(HSetInternal <T> other)
        {
            if (other == null || Count != other.Count)
            {
                return(false);
            }
            var iterx = GetEnumerator();
            var itery = other.GetEnumerator();

            var eq = EqualityComparer <T> .Default;

            for (int i = 0; i < count; i++)
            {
                iterx.MoveNext();
                itery.MoveNext();
                if (!eq.Equals(iterx.Current, itery.Current))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #6
0
        public bool IsProperSubsetOf(IEnumerable <T> other)
        {
            if (IsEmpty)
            {
                return(other.Any());
            }

            var otherSet = new HSetInternal <T>(other);

            if (Count >= otherSet.Count)
            {
                return(false);
            }

            int  matches    = 0;
            bool extraFound = false;

            foreach (var item in otherSet)
            {
                if (Contains(item))
                {
                    matches++;
                }
                else
                {
                    extraFound = true;
                }

                if (matches == Count && extraFound)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #7
0
 /// <summary>
 /// Ctor that takes an initial (distinct) set of items
 /// </summary>
 /// <param name="items"></param>
 internal HSet(IEnumerable <T> items, bool checkUniqueness = false)
 {
     value = new HSetInternal <T>(items, checkUniqueness);
 }
コード例 #8
0
 static HSet <U> Wrap <U>(HSetInternal <U> value) =>
 new HSet <U>(value);
コード例 #9
0
 HSet <T> Wrap(HSetInternal <T> value) =>
 new HSet <T>(value);
コード例 #10
0
 internal HSet(HSetInternal <T> value)
 {
     this.value = value;
 }