Esempio n. 1
0
        public override bool Equals(ValueTreeNode other)
        {
            var otherBranch = other as ValueTreeBranchNode <TKey>;

            //The other node must be the same type as this one
            if (otherBranch == null)
            {
                return(false);
            }

            //Return true for reference equality
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            //The number of child nodes must be equal
            if (_childNodesDictionary.Count != otherBranch._childNodesDictionary.Count)
            {
                return(false);
            }

            //Each child node in the other node must be equal to a child with the same key of this node
            ValueTreeNode otherChildNode;

            return
                (_childNodesDictionary
                 .All(
                     pair =>
                     otherBranch._childNodesDictionary.TryGetValue(pair.Key, out otherChildNode) &&
                     pair.Value.Equals(otherChildNode)
                     ));
        }
Esempio n. 2
0
        public override bool Equals(ValueTreeNode other)
        {
            var otherLeaf = other as ValueTreeLeafNode <TValue>;

            if (otherLeaf == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                (IsLeafNode == otherLeaf.IsLeafNode &&
                 Value.Equals(otherLeaf.Value));
        }