Example #1
0
    //*************************************************************************
    //************** From now on repOK()  *************************************
    //*************************************************************************

    public boolean repOK()
    {
        if (header == null)
        {
            return(false);
        }
        if (header.object_value != null)
        {
            return(false);
        }

        RoopsSet visited = new RoopsSet();

        visited.add(header);
        LinkedListNode current = header;

        while (true)
        {
            LinkedListNode next = current.next;
            if (next == null)
            {
                return(false);
            }
            if (next.previous != current)
            {
                return(false);
            }
            current = next;
            if (!visited.add(next))
            {
                break;
            }
        }
        if (current != header)
        {
            return(false);
        }

        if (visited.getSize() - 1 != size)
        {
            return(false);
        }

        return(true);
    }
Example #2
0
    //*************************************************************************
    //************** From now on repOK()  *************************************
    //*************************************************************************

    public boolean repOK()
    {
        RoopsSet visited = new RoopsSet();

        SinglyLinkedListNode current = header;

        while (true)
        {
            SinglyLinkedListNode next = current;
            if (next == null)
            {
                break;
            }

            if (!visited.add(next))
            {
                return(false);
            }

            current = current.next;
        }

        return(true);
    }
Example #3
0
    //*************************************************************************
    //************** From now on repOK()  *************************************
    //*************************************************************************

    public boolean repOK()
    {
        RoopsSet  allNodes = new RoopsSet();
        RoopsList parent_headers_to_visit = new RoopsList();

        if (min != null)
        {
            // check first level
            {
                int         child_cound = 0;
                FibHeapNode curr        = min;
                do
                {
                    if (curr.left.right != curr)
                    {
                        return(false);
                    }

                    if (curr.parent != null)
                    {
                        return(false);
                    }

                    if (curr.child != null)
                    {
                        parent_headers_to_visit.add(curr);
                    }

                    if (!allNodes.add(curr))
                    {
                        return(false);                       // repeated node
                    }
                    curr = curr.left;
                    child_cound++;
                } while (curr != min);
            }

            while (!parent_headers_to_visit.isEmpty())
            {
                // check other levels

                FibHeapNode node = (FibHeapNode)parent_headers_to_visit.get(0);
                parent_headers_to_visit.remove(0);

                int         node_count = 0;
                FibHeapNode curr_node  = node.child;
                do
                {
                    if (curr_node.left.right != curr_node)
                    {
                        return(false);
                    }

                    if (curr_node.parent != null)
                    {
                        return(false);
                    }

                    if (curr_node.child != null)
                    {
                        parent_headers_to_visit.add(curr_node);
                    }

                    if (curr_node.cost > node.cost)
                    {
                        return(false);
                    }

                    if (!allNodes.add(curr_node))
                    {
                        return(false);                        // repeated node
                    }
                    curr_node = curr_node.left;
                    node_count++;
                } while (curr_node != node.child);

                if (node_count != node.degree)
                {
                    return(false);
                }
            }
        }

        if (allNodes.getSize() != this.n)
        {
            return(false);
        }

        return(true);
    }
Example #4
0
    //*************************************************************************
    //************** From now on repOK()  *************************************
    //*************************************************************************
    public boolean repOK()
    {
        RoopsSet visited = new RoopsSet();

            SinglyLinkedListNode current = header;

            while (true)
            {
                SinglyLinkedListNode next = current;
                if (next == null)
                    break;

                if (!visited.add(next))
                    return false;

                current = current.next;
            }

            return true;
    }
Example #5
0
    //*************************************************************************
    //************************* From now on repOk  ****************************
    //*************************************************************************.
    public boolean repOK()
    {
        if (root == null)
            return size == 0;

        if (root.parent != null)
            return false;

        RoopsSet visited = new RoopsSet();
        visited.add(root);
        RoopsList workList = new RoopsList();
        workList.add(root);

        while (workList.getSize() > 0) {

            TreeSetEntry current = (TreeSetEntry) workList.get(0);
            workList.remove(0);

            TreeSetEntry cl = current.left;
            if (cl != null) {
                if (!visited.add(cl))
                    return false;
                if (cl.parent != current)
                    return false;
                workList.add(cl);
            }
            TreeSetEntry cr = current.right;
            if (cr != null) {
                if (!visited.add(cr))
                    return false;
                if (cr.parent != current)
                    return false;
                workList.add(cr);
            }
        }

        if (visited.getSize() != size)
            return false;

        if (!repOK_Colors())
            return false;

        return repOK_KeysAndValues();
    }
Example #6
0
    //*************************************************************************
    //************************* From now on repOk  ****************************
    //*************************************************************************.
    public boolean repOK()
    {
        if (root == null)
        {
            return(size == 0);
        }

        if (root.parent != null)
        {
            return(false);
        }

        RoopsSet visited = new RoopsSet();

        visited.add(root);
        RoopsList workList = new RoopsList();

        workList.add(root);

        while (workList.getSize() > 0)
        {
            TreeSetEntry current = (TreeSetEntry)workList.get(0);
            workList.remove(0);

            TreeSetEntry cl = current.left;
            if (cl != null)
            {
                if (!visited.add(cl))
                {
                    return(false);
                }
                if (cl.parent != current)
                {
                    return(false);
                }
                workList.add(cl);
            }
            TreeSetEntry cr = current.right;
            if (cr != null)
            {
                if (!visited.add(cr))
                {
                    return(false);
                }
                if (cr.parent != current)
                {
                    return(false);
                }
                workList.add(cr);
            }
        }

        if (visited.getSize() != size)
        {
            return(false);
        }

        if (!repOK_Colors())
        {
            return(false);
        }

        return(repOK_KeysAndValues());
    }
Example #7
0
    //*************************************************************************
    //************** From now on repOK()  *************************************
    //*************************************************************************
    public boolean repOK()
    {
        if (header == null)
                return false;
            if (header.object_value != null)
                return false;

            RoopsSet visited = new RoopsSet();
            visited.add(header);
            LinkedListNode current = header;

            while (true)
            {
                LinkedListNode next = current.next;
                if (next == null)
                    return false;
                if (next.previous != current)
                    return false;
                current = next;
                if (!visited.add(next))
                    break;
            }
            if (current != header)
                return false;

            if (visited.getSize() - 1 != size)
                return false;

            return true;
    }
Example #8
0
    //*************************************************************************
    //************** From now on repOk()  *************************************
    //*************************************************************************

    public boolean repOK()
    {
        RoopsSet     allNodes = new RoopsSet();
        RoopsIntList allData  = new RoopsIntList();
        RoopsStack   stack    = new RoopsStack();

        if (root != null)
        {
            stack.push(root);
        }

        while (stack.getSize() > 0)
        {
            AvlNode node = (AvlNode)stack.pop();

            if (!allNodes.add(node))
            {
                return(false);                // Not acyclic.
            }
            if (!allData.add(node.element))
            {
                return(false);                // Repeated data.
            }
            // check balance
            int l_Height;
            if (node.left == null)
            {
                l_Height = 0;
            }
            else
            {
                l_Height = node.left.height;
            }

            int r_Height;
            if (node.right == null)
            {
                r_Height = 0;
            }
            else
            {
                r_Height = node.right.height;
            }

            int difference = l_Height - r_Height;
            if (difference < -1 || difference > 1)
            {
                return(false);                // Not balanced.
            }
            int max;
            if (l_Height > r_Height)
            {
                max = l_Height;
            }
            else
            {
                max = r_Height;
            }

            if (node.height != 1 + max)
            {
                return(false);                // Wrong height.
            }
            // visit descendants
            if (node.left != null)
            {
                stack.push(node.left);
            }

            if (node.right != null)
            {
                stack.push(node.right);
            }
        }

        if (!repOK_isOrdered(root))
        {
            return(false);
        }


        return(true);
    }
Example #9
0
    //*************************************************************************
    //************** From now on repOk()  *************************************
    //*************************************************************************
    public boolean repOK()
    {
        RoopsSet allNodes = new RoopsSet();
        RoopsIntList allData = new RoopsIntList();
                RoopsStack stack = new RoopsStack();
        if (root != null) {
                  stack.push(root);
                }

        while (stack.getSize()>0) {

            AvlNode node = (AvlNode) stack.pop();

            if (!allNodes.add(node))
                return false; // Not acyclic.

            if (!allData.add(node.element))
                return false; // Repeated data.

            // check balance
            int l_Height;
                        if (node.left == null)
                          l_Height = 0 ;
                        else
                          l_Height = node.left.height;

            int r_Height;
                        if (node.right == null)
                          r_Height = 0 ;
                        else
                          r_Height = node.right.height;

            int difference = l_Height - r_Height;
            if (difference < -1 || difference > 1)
                return false; // Not balanced.

            int max;
                        if (l_Height > r_Height)
                          max = l_Height ;
                        else
                          max = r_Height;

            if (node.height != 1 + max)
                return false; // Wrong height.

                        // visit descendants
            if (node.left != null)
                stack.push(node.left);

            if (node.right != null)
                stack.push(node.right);

        }

        if (!repOK_isOrdered(root))
            return false;

        return true;
    }
Example #10
0
    //*************************************************************************
    //************** From now on repOK()  *************************************
    //*************************************************************************
    public boolean repOK()
    {
        RoopsSet allNodes = new RoopsSet();
        RoopsList parent_headers_to_visit = new RoopsList();

        if (min != null) {

            // check first level
            {
                int child_cound = 0;
                FibHeapNode curr = min;
                do  {
                    if (curr.left.right != curr)
                        return false;

                    if (curr.parent != null)
                        return false;

                    if (curr.child != null)
                        parent_headers_to_visit.add(curr);

                    if (!allNodes.add(curr))
                        return false;// repeated node

                    curr = curr.left;
                    child_cound++;

                } while (curr!=min);

            }

            while (!parent_headers_to_visit.isEmpty()) {

                // check other levels

                FibHeapNode node = (FibHeapNode) parent_headers_to_visit.get(0);
                parent_headers_to_visit.remove(0);

                int node_count = 0;
                FibHeapNode curr_node = node.child;
                do {
                    if (curr_node.left.right != curr_node)
                        return false;

                    if (curr_node.parent != null)
                        return false;

                    if (curr_node.child != null)
                        parent_headers_to_visit.add(curr_node);

                    if (curr_node.cost>node.cost)
                        return false;

                    if (!allNodes.add(curr_node))
                        return false; // repeated node

                    curr_node = curr_node.left;
                    node_count++;

                } while (curr_node != node.child);

                if (node_count != node.degree)
                    return false;

            }

        }

        if (allNodes.getSize() != this.n)
            return false;

        return true;
    }