Example #1
0
        public static void Main()
        {
            var set1 = new JSet <string>();
            var set2 = new JSet <string>();

            set1.Add("one");
            set1.Add("two");
            set1.Add("three");

            set2.Add("three");
            set2.Add("four");

            Console.WriteLine(set1);
            Console.WriteLine(set2);

            Console.WriteLine(set1.Intersect(set2));
            Console.WriteLine(set2.Intersect(set1));

            Console.WriteLine(set1.Union(set2));
            Console.WriteLine(set2.Union(set1));

            set1.Remove("five");
            set1.Remove("two");
            Console.WriteLine(set1);

            Console.WriteLine(set1.Find("one"));
            Console.WriteLine(set1.Find("two"));

            Console.WriteLine(set1.Count);
        }
Example #2
0
        /// <summary>
        /// Produces a JSet of <typeparamref name="T"/> values united with another JSet <typeparamref name="K"/> key
        /// </summary>
        /// <param name="other">The other JSet to union with</param>
        /// <returns><typeparamref name="JSet<T>"/></returns>
        public JSet <T> Union(JSet <T> other)
        {
            JSet <T> newSet = new JSet <T>();

            foreach (var element in this)
            {
                newSet.Add(element);
            }

            foreach (var element in other)
            {
                newSet.Add(element);
            }

            return(newSet);
        }
Example #3
0
        /// <summary>
        /// Produces a JSet of <typeparamref name="T"/> values intersected with another JSet <typeparamref name="K"/> key
        /// </summary>
        /// <param name="other">The other JSet to intersect with</param>
        /// <returns><typeparamref name="JSet<T>"/></returns>
        public JSet <T> Intersect(JSet <T> other)
        {
            JSet <T> newSet = new JSet <T>();

            foreach (var element in this)
            {
                foreach (var otherElement in other)
                {
                    if (element.Equals(otherElement))
                    {
                        newSet.Add(element);
                    }
                }
            }

            return(newSet);
        }