コード例 #1
0
ファイル: TreeSet.cs プロジェクト: taoxiease/roops
    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);
    }
コード例 #2
0
    public RoopsList(RoopsList <T> rhs)
    {
        len    = rhs.len;
        arrlen = rhs.arrlen;

        for (int i = 0; i < len; i++)
        {
            arr[i] = rhs.arr[i];
        }
    }
コード例 #3
0
ファイル: BinTree.cs プロジェクト: taoxiease/roops
    private boolean repOK_isAcyclic()
    {
        RoopsList visited = new RoopsList();

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

        workList.add(root);
        while (!workList.isEmpty())
        {
            BinTreeNode current = (BinTreeNode)workList.get(0);
            workList.remove(0);
            if (current.left != null)
            {
                // checks that the tree has no cycle
                if (visited.contains(current.left))
                {
                    return(false);
                }
                else
                {
                    visited.add(current.left);
                }

                workList.add(current.left);
            }
            if (current.right != null)
            {
                // checks that the tree has no cycle
                if (visited.contains(current.right))
                {
                    return(false);
                }
                else
                {
                    visited.add(current.right);
                }

                workList.add(current.right);
            }
        }
        return(true);
    }
コード例 #4
0
ファイル: BinTree.cs プロジェクト: taoxiease/roops
    private boolean repOK_parentsAllRight()
    {
        RoopsList workList = new RoopsList();

        workList.add(root);

        while (!workList.isEmpty())
        {
            BinTreeNode current = (BinTreeNode)workList.get(0);
            workList.remove(0);
            if (current.left != null)
            {
                if (current.left.parent != current)
                {
                    return(false);
                }
                else
                {
                    workList.add(current.left);
                }
            }
            if (current.right != null)
            {
                if (current.right.parent != current)
                {
                    return(false);
                }
                else
                {
                    workList.add(current.right);
                }
            }
        }

        return(true);
    }
コード例 #5
0
ファイル: BinTree.cs プロジェクト: taoxiease/roops
    private boolean repOK_isAcyclic()
    {
        RoopsList visited = new RoopsList();
          visited.add(root);
          RoopsList workList = new RoopsList();
          workList.add(root);
          while (!workList.isEmpty()) {
        BinTreeNode current = (BinTreeNode)workList.get(0);
        workList.remove(0);
        if (current.left != null) {
          // checks that the tree has no cycle
          if (visited.contains(current.left))
            return false;
          else
            visited.add(current.left);

          workList.add(current.left);
        }
        if (current.right != null) {
          // checks that the tree has no cycle
          if (visited.contains(current.right))
            return false;
          else
        visited.add(current.right);

          workList.add(current.right);
        }
          }
          return true;
    }
コード例 #6
0
ファイル: TreeSet.cs プロジェクト: taoxiease/roops
    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;
    }
コード例 #7
0
ファイル: TreeSet.cs プロジェクト: taoxiease/roops
    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;
    }
コード例 #8
0
ファイル: TreeSet.cs プロジェクト: taoxiease/roops
    //*************************************************************************
    //************************* 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();
    }
コード例 #9
0
ファイル: RoopsMap.cs プロジェクト: taoxiease/roops
 public RoopsMap()
 {
     keys = new RoopsList();
     vals = new RoopsList();
 }
コード例 #10
0
ファイル: FibHeap.cs プロジェクト: taoxiease/roops
    //*************************************************************************
    //************** 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;
    }
コード例 #11
0
 public RoopsMap()
 {
     keys = new RoopsList();
     vals = new RoopsList();
 }
コード例 #12
0
ファイル: BinomialHeap.cs プロジェクト: taoxiease/roops
    //*************************************************************************
    //************************* 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);
    }
コード例 #13
0
 public RoopsNaiveMap()
 {
     keys    = new RoopsList <K>();
     vals    = new RoopsList <V>();
     entries = new RoopsList <Entry <K, V> >();
 }
コード例 #14
0
ファイル: BinomialHeap.cs プロジェクト: taoxiease/roops
    private static boolean repOK_nodeRepOk(BinomialHeapNode Node)
    {
        RoopsList seen = new RoopsList();

        if (Node!=null) {

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

            if (!repOK_ordered(Node))
                return false;

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

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

            BinomialHeapNode ns = Node.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;
              }

        }

        return true;
    }
コード例 #15
0
ファイル: BinomialHeap.cs プロジェクト: taoxiease/roops
    private static boolean repOK_isAcyclic(BinomialHeapNode start, RoopsList seen)
    {
        if (seen.contains(start))
             return false;

         if (start.degree<0)
             return false;

         seen.add(start);

         BinomialHeapNode child = start.child;

         int child_count = 0;

         while (child!=null) {

             child_count++;

             if (child.parent != start)
                 return false;

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

             if (child.sibling!=null) {
                 if (child.degree<=child.sibling.degree)
                     return false;
             }
             child = child.sibling;
         }

         if (start.degree!=child_count)
             return false;

         if (start.child!=null) {
             int tam_child=1;
             if (start.child.child!=null) {
                 BinomialHeapNode curr = start.child.child;
                 while (curr!=null) {
                   tam_child+= repOK_count_nodes(start.child.child);
                   curr = curr.sibling;
                 }
             }

             int tam_sibling=1;
             if (start.child.sibling!=null) {
                 BinomialHeapNode curr = start.child.sibling;
                 while (curr!=null) {
                   tam_sibling+= repOK_count_nodes(start.child.sibling);
          			       curr = curr.sibling;
                 }
             }

             if (tam_child!=tam_sibling)
                 return false;

         }

         return true;
    }
コード例 #16
0
ファイル: BinomialHeap.cs プロジェクト: taoxiease/roops
    //*************************************************************************
    //************************* 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;
    }
コード例 #17
0
ファイル: BinTree.cs プロジェクト: taoxiease/roops
    private boolean repOK_parentsAllRight()
    {
        RoopsList workList = new RoopsList();
          workList.add(root);

          while(!workList.isEmpty()) {
        BinTreeNode current = (BinTreeNode)workList.get(0);
        workList.remove(0);
        if (current.left != null) {
          if (current.left.parent != current)
            return false;
          else
            workList.add(current.left);
        }
        if (current.right != null) {
          if (current.right.parent != current)
            return false;
          else
            workList.add(current.right);
        }
          }

          return true;
    }
コード例 #18
0
ファイル: BinomialHeap.cs プロジェクト: taoxiease/roops
    private static boolean repOK_isAcyclic(BinomialHeapNode start, RoopsList seen)
    {
        if (seen.contains(start))
        {
            return(false);
        }

        if (start.degree < 0)
        {
            return(false);
        }

        seen.add(start);

        BinomialHeapNode child = start.child;

        int child_count = 0;

        while (child != null)
        {
            child_count++;

            if (child.parent != start)
            {
                return(false);
            }

            if (!repOK_isAcyclic(child, seen))
            {
                return(false);
            }

            if (child.sibling != null)
            {
                if (child.degree <= child.sibling.degree)
                {
                    return(false);
                }
            }
            child = child.sibling;
        }

        if (start.degree != child_count)
        {
            return(false);
        }

        if (start.child != null)
        {
            int tam_child = 1;
            if (start.child.child != null)
            {
                BinomialHeapNode curr = start.child.child;
                while (curr != null)
                {
                    tam_child += repOK_count_nodes(start.child.child);
                    curr       = curr.sibling;
                }
            }

            int tam_sibling = 1;
            if (start.child.sibling != null)
            {
                BinomialHeapNode curr = start.child.sibling;
                while (curr != null)
                {
                    tam_sibling += repOK_count_nodes(start.child.sibling);
                    curr         = curr.sibling;
                }
            }

            if (tam_child != tam_sibling)
            {
                return(false);
            }
        }

        return(true);
    }
コード例 #19
0
ファイル: RoopsStack.cs プロジェクト: taoxiease/roops
 public RoopsStack()
 {
     list = new RoopsList();
 }
コード例 #20
0
ファイル: RoopsStack.cs プロジェクト: taoxiease/roops
 public RoopsStack()
 {
     list = new RoopsList();
 }
コード例 #21
0
ファイル: BinomialHeap.cs プロジェクト: taoxiease/roops
    private static boolean repOK_nodeRepOk(BinomialHeapNode Node)
    {
        RoopsList seen = new RoopsList();

        if (Node != null)
        {
            if (!repOK_isAcyclic(Node, seen))
            {
                return(false);
            }

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

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

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

            BinomialHeapNode ns = Node.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;
            }
        }

        return(true);
    }
コード例 #22
0
ファイル: TreeSet.cs プロジェクト: taoxiease/roops
    //*************************************************************************
    //************************* 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());
    }
コード例 #23
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);
    }
コード例 #24
0
ファイル: TreeSet.cs プロジェクト: taoxiease/roops
    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);
    }