Beispiel #1
0
 internal static void AddValue <T>(ref ISet <T> references, T value)
 {
     if (references == null)
     {
         references = new SetOfOne <T>(value);
     }
     else if (references is SetOfOne <T> )
     {
         if (!references.Contains(value))
         {
             references = new SetOfTwo <T>(((SetOfOne <T>)references).Value, value);
         }
     }
     else if (references is SetOfTwo <T> )
     {
         if (!references.Contains(value))
         {
             references = new HashSet <T>(references);
             references.Add(value);
         }
     }
     else
     {
         references.Add(value);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Returns the union of the new two sets as a new set tracking whether
        /// or not self is a locally created HashSet.
        /// </summary>
        public static ISet <Namespace> Union(this ISet <Namespace> self, ISet <Namespace> value, ref bool madeSet)
        {
            Namespace selfOne, valueOne;

            if (self.Count == 0)
            {
                return(value);
            }
            else if (value.Count == 0)
            {
                return(self);
            }
            else if ((selfOne = self as Namespace) != null)
            {
                if ((valueOne = value as Namespace) != null)
                {
                    if (object.ReferenceEquals(selfOne, valueOne))
                    {
                        return(selfOne);
                    }
                    var res = new SetOfTwo <Namespace>(selfOne, valueOne);
                    return(res);
                }
                else
                {
                    var res = new HashSet <Namespace>(value);
                    res.Add(selfOne);
                    return(res);
                }
            }
            else if ((valueOne = value as Namespace) != null)
            {
                var res = new HashSet <Namespace>(self);
                res.Add(valueOne);
                return(res);
            }

            if (!madeSet)
            {
                self    = new HashSet <Namespace>(self);
                madeSet = true;
            }
            self.UnionWith(value);
            return(self);
        }