Ejemplo n.º 1
0
        public static Eqclass <T> Make(T item)
        {
            if (!dict.Find(ref item, out var result))
            {
                dict[item] = result = new Eqclass <T>(item);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            var x = Eqclass <int> .Make(3);

            var y = Eqclass <int> .Make(4);

            var z = Eqclass <int> .Make(5);

            x.Union(y);
            y.Union(z);
            Console.WriteLine(x.Find().Item);
            Console.WriteLine(y.Find().Item);
            Console.WriteLine(z.Find().Item);
        }
Ejemplo n.º 3
0
        public void Union(Eqclass <T> that)
        {
            var thatRep = that.Find();
            var thisRep = Find();

            if (thatRep != thisRep)
            {
                if (thatRep._rank == thisRep._rank)
                {
                    thisRep._link = thatRep;
                    thatRep._rank++;
                }
                else if (thatRep._rank > thisRep._rank)
                {
                    thisRep._link = thatRep;
                }
                else
                {
                    thatRep._link = thisRep;
                }
            }
        }