Exemple #1
0
    public Object pop()
    {
        int    last_index = list.getSize() - 1;
        Object ret_val    = list.get(last_index);

        list.remove(last_index);
        return(ret_val);
    }
Exemple #2
0
    public boolean repOK_KeysAndValues()
    {
        int min = repOK_findMin(root);
        int max = repOK_findMax(root);

        if (!repOK_orderedKeys(root, min - 1, max + 1))
        {
            return(false);
        }

        // touch values
        RoopsList workList = new RoopsList();

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

            if (current.left != null)
            {
                workList.add(current.left);
            }
            if (current.right != null)
            {
                workList.add(current.right);
            }
        }
        return(true);
    }
Exemple #3
0
    //*************************************************************************
    //************************* From now on repOK  ****************************
    //*************************************************************************.

    public boolean repOK()
    {
        RoopsList seen = new RoopsList();

        if (this.Nodes != null)
        {
            if (!repOK_isAcyclic(this.Nodes, seen))
            {
                return(false);
            }

            if (!repOK_ordered(this.Nodes))
            {
                return(false);
            }

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

            if (this.Nodes.sibling != null)
            {
                if (this.Nodes.degree >= this.Nodes.sibling.degree)
                {
                    return(false);
                }
            }

            BinomialHeapNode ns = this.Nodes.sibling;
            while (ns != null)
            {
                if (!repOK_isAcyclic(ns, seen))
                {
                    return(false);
                }

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

                if (ns.sibling != null)
                {
                    if (ns.degree >= ns.sibling.degree)
                    {
                        return(false);
                    }
                }


                if (!repOK_ordered(ns))
                {
                    return(false);
                }


                ns = ns.sibling;
            }
        }

        int node_count = seen.getSize();

        if (this.size != node_count)
        {
            return(false);
        }

        return(true);
    }
Exemple #4
0
    public boolean repOK_KeysAndValues()
    {
        int min = repOK_findMin(root);
        int max = repOK_findMax(root);
        if (!repOK_orderedKeys(root, min-1, max+1))
            return false;

        // touch values
        RoopsList workList = new RoopsList();
        workList.add(root);
        while (workList.getSize() > 0) {
            TreeSetEntry current = (TreeSetEntry) workList.get(0);
            workList.remove(0);

            if (current.left != null)
                workList.add(current.left);
            if (current.right != null)
                workList.add(current.right);
        }
        return true;
    }
Exemple #5
0
    public boolean repOK_Colors()
    {
        RoopsList workList = new RoopsList();
        workList.add(root);
        while (workList.getSize() > 0) {
            TreeSetEntry current = (TreeSetEntry) workList.get(0);
            workList.remove(0);
            TreeSetEntry cl = current.left;
            TreeSetEntry cr = current.right;
            if (current.color == RED) {
                if (cl != null && cl.color == RED)
                    return false;
                if (cr != null && cr.color == RED)
                    return false;
            }
            if (cl != null)
                workList.add(cl);
            if (cr != null)
                workList.add(cr);
        }

        int numberOfBlack = -1;
        RoopsList workList2 = new RoopsList();

        workList2.add(new Pair(root, 0));

        while (workList2.getSize() > 0) {
            Pair p = (Pair) workList2.get(0);
            workList2.remove(0);
            TreeSetEntry e = p.e;
            int n = p.n;
            if (e != null && e.color == BLACK)
                n++;
            if (e == null) {
                if (numberOfBlack == -1)
                    numberOfBlack = n;
                else if (numberOfBlack != n)
                    return false;
            } else {
                workList2.add(new Pair(e.left, n));
                workList2.add(new Pair(e.right, n));
            }
        }
        return true;
    }
Exemple #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();
    }
Exemple #7
0
    public boolean repOK_Colors()
    {
        RoopsList workList = new RoopsList();

        workList.add(root);
        while (workList.getSize() > 0)
        {
            TreeSetEntry current = (TreeSetEntry)workList.get(0);
            workList.remove(0);
            TreeSetEntry cl = current.left;
            TreeSetEntry cr = current.right;
            if (current.color == RED)
            {
                if (cl != null && cl.color == RED)
                {
                    return(false);
                }
                if (cr != null && cr.color == RED)
                {
                    return(false);
                }
            }
            if (cl != null)
            {
                workList.add(cl);
            }
            if (cr != null)
            {
                workList.add(cr);
            }
        }

        int       numberOfBlack = -1;
        RoopsList workList2     = new RoopsList();

        workList2.add(new Pair(root, 0));

        while (workList2.getSize() > 0)
        {
            Pair p = (Pair)workList2.get(0);
            workList2.remove(0);
            TreeSetEntry e = p.e;
            int          n = p.n;
            if (e != null && e.color == BLACK)
            {
                n++;
            }
            if (e == null)
            {
                if (numberOfBlack == -1)
                {
                    numberOfBlack = n;
                }
                else if (numberOfBlack != n)
                {
                    return(false);
                }
            }
            else
            {
                workList2.add(new Pair(e.left, n));
                workList2.add(new Pair(e.right, n));
            }
        }
        return(true);
    }
Exemple #8
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());
    }
Exemple #9
0
    //*************************************************************************
    //************************* From now on repOK  ****************************
    //*************************************************************************.
    public boolean repOK()
    {
        RoopsList seen = new RoopsList();

        if (this.Nodes!=null) {

            if (!repOK_isAcyclic(this.Nodes, seen))
                return false;

            if (!repOK_ordered(this.Nodes))
                return false;

            if (this.Nodes.parent!=null)
                return false;

            if (this.Nodes.sibling!=null) {
                if (this.Nodes.degree >= this.Nodes.sibling.degree)
                    return false;
            }

            BinomialHeapNode ns = this.Nodes.sibling;
            while (ns != null) {

                if (!repOK_isAcyclic(ns, seen))
                    return false;

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

                if (ns.sibling!=null) {
                      if (ns.degree>=ns.sibling.degree)
                          return false;
                  }

                  if (!repOK_ordered(ns))
                      return false;

                  ns = ns.sibling;
              }

        }

        int node_count = seen.getSize();

        if (this.size!=node_count)
            return false;

        return true;
    }