Example #1
0
        public bool Subset(LinkedSet <T> set, bool UseLinq = false)
        {
            if (UseLinq)
            {
                return(this.set.All(i => set.set.Contains(i)));
            }
            else
            {
                foreach (var thisItem in this.set)
                {
                    var equals = false;

                    foreach (var setItem in set.set)
                    {
                        if (thisItem.Equals(setItem))
                        {
                            equals = true;
                            break;
                        }
                    }

                    if (!equals)
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
Example #2
0
 public LinkedSet <T> SymmetricDifference(LinkedSet <T> set, bool UseLinq = false)
 {
     if (UseLinq)
     {
         return(new LinkedSet <T>(this.set.Except(set.set).Union(set.set.Except(this.set))));
     }
     else
     {
         return(this.Difference(set).Union(set.Difference(this)));
     }
 }
Example #3
0
 public LinkedSet <T> Difference(LinkedSet <T> set, bool UseLinq = false)
 {
     if (UseLinq)
     {
         return(new LinkedSet <T>(this.set.Except(set.set)));
     }
     else
     {
         var result = new LinkedSet <T>(this.set);
         foreach (var item in set.set)
         {
             result.Remove(item);
         }
         return(result);
     }
 }
Example #4
0
        public LinkedSet <T> Union(LinkedSet <T> set, bool UseLinq = false)
        {
            if (UseLinq)
            {
                return(new LinkedSet <T>(this.set.Union(set.set)));
            }
            else
            {
                LinkedSet <T> result = new LinkedSet <T>(this.set);
                foreach (var item in set.set)
                {
                    result.Add(item);
                }

                return(result);
            }
        }
Example #5
0
        public LinkedSet <T> Intersection(LinkedSet <T> set, bool UseLinq = false)
        {
            if (UseLinq)
            {
                return(new LinkedSet <T>(this.set.Intersect(set.set)));
            }
            else
            {
                LinkedSet <T> result = new LinkedSet <T>();
                List <T>      smallSet;
                List <T>      bigSet;

                if (Count < set.Count)
                {
                    smallSet = this.set;
                    bigSet   = set.set;
                }
                else
                {
                    smallSet = set.set;
                    bigSet   = this.set;
                }

                foreach (var itemSmall in smallSet)
                {
                    foreach (var itemBig in bigSet)
                    {
                        if (itemSmall.Equals(itemBig))
                        {
                            result.Add(itemSmall);
                            break;
                        }
                    }
                }

                return(result);
            }
        }