Ejemplo n.º 1
0
            /// <summary>
            /// Equals
            /// </summary>
            public bool Equals(DisjointSets <T> x, DisjointSets <T> y)
            {
                if (ReferenceEquals(x, y))
                {
                    return(true);
                }
                else if (x is null || y is null)
                {
                    return(false);
                }

                if (x.ItemsComparer != y.ItemsComparer)
                {
                    return(false);
                }

                if (x.m_Items.Count != y.m_Items.Count)
                {
                    return(false);
                }

                for (int i = 0; i < x.m_Items.Count; ++i)
                {
                    if (!x.m_Items[i].SetEquals(y.m_Items[i]))
                    {
                        return(false);
                    }
                }

                return(true);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Equals
            /// </summary>
            public bool Equals(DisjointSets <T> x, DisjointSets <T> y)
            {
                if (ReferenceEquals(x, y))
                {
                    return(true);
                }
                else if (x is null || y is null)
                {
                    return(false);
                }

                if (x.ItemsComparer != y.ItemsComparer)
                {
                    return(false);
                }

                if (x.m_Items.Count != y.m_Items.Count)
                {
                    return(false);
                }

                var data = x.m_Items
                           .GroupBy(item => item.Count)
                           .ToDictionary(group => group.Key, group => group.ToList());

                foreach (var item in y.m_Items)
                {
                    if (!data.TryGetValue(item.Count, out var list))
                    {
                        return(false);
                    }

                    if (!list.Any(hs => hs.SetEquals(item)))
                    {
                        return(false);
                    }
                }

                return(true);
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Hash Code
 /// </summary>
 public int GetHashCode(DisjointSets <T> obj) => obj is null ? 0 : obj.Count;
Ejemplo n.º 4
0
 /// <summary>
 /// Equals
 /// </summary>
 public bool Equals(DisjointSets <T> other) => UnOrderedComparer.Equals(this, other);