示例#1
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);
            }
        }
示例#2
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);
            }
        }