Exemple #1
0
        //      #define NULL_OR_EQUALID(a,b) ((a==0 && b==0) || ((a!=0 && b!=0) && (a.getID()==b.getID())))

        ///** Equality operator. Does not do a deep compare */
        //bool operator==(const SafraTreeNode& other) {
        //  if (!(_id==other._id)) {return false;}
        //  if (!(_final_flag==other._final_flag)) {return false;}
        //  if (!(_childCount==other._childCount)) {return false;}
        //  if (!(_labeling==other._labeling)) {return false;}
        //  if (!NULL_OR_EQUALID(_parent, other._parent)) {return false;}
        //  if (!NULL_OR_EQUALID(_olderBrother, other._olderBrother)) {return false;}
        //  if (!NULL_OR_EQUALID(_youngerBrother, other._youngerBrother)) {return false;}
        //  if (!NULL_OR_EQUALID(_oldestChild, other._oldestChild)) {return false;}
        //  if (!NULL_OR_EQUALID(_youngestChild, other._youngestChild)) {return false;}

        //  return true;
        //}

        /**
         * Equality operator ignoring the name of the nodes, doing a deep compare
         * (checks that all children are also structurally equal.
         */
        public bool structural_equal_to(SafraTreeNode other)
        {
            if (!(_final_flag == other._final_flag))
            {
                return(false);
            }
            if (!(_childCount == other._childCount))
            {
                return(false);
            }
            if (!(_labeling == other._labeling))
            {
                return(false);
            }

            if (_childCount > 0)
            {
                SafraTreeNode this_child  = this._oldestChild;
                SafraTreeNode other_child = other._oldestChild;

                do
                {
                    if (!this_child.structural_equal_to(other_child))
                    {
                        return(false);
                    }

                    this_child  = this_child._youngerBrother;
                    other_child = other_child._youngerBrother;
                } while (this_child != null && other_child != null);

                System.Diagnostics.Debug.Assert(this_child == null && other_child == null);
            }
            return(true);
        }
Exemple #2
0
        /**
         * Checks equality when ignoring the node names.
         */
        public bool structural_equal_to(SafraTree other)
        {
            if (other.MAX_NODES != MAX_NODES)
            {
                return(false);
            }

            SafraTreeNode this_root  = this.getRootNode();
            SafraTreeNode other_root = other.getRootNode();

            if (this_root == null || other_root == null)
            {
                // return true if both are 0
                return(this_root == other_root);
            }

            return(this_root.structural_equal_to(other_root));
        }