Beispiel #1
0
            public EnumerateNear(Bspt bspt, Bspt.Tuple center, double distance)
            {
                this.distance = distance;
                this.center   = center;

                stack = new Node[Bspt.stackDepth];
                sp    = 0;
                Bspt.Element ele = bspt.eleRoot;
                while (ele is Node)
                {
                    Node node = (Node)ele;
                    if (center.getDimValue(node.dim) - distance <= node.splitValue)
                    {
                        if (sp == Bspt.stackDepth)
                        {
                            System.Console.Out.WriteLine("Bspt.EnumerateNear tree stack overflow");
                        }
                        stack[sp++] = node;
                        ele         = node.eleLE;
                    }
                    else
                    {
                        ele = node.eleGE;
                    }
                }
                leaf = (Leaf)ele;
                i    = 0;
            }
Beispiel #2
0
 public EnumerateSphere(Bspt bspt, Bspt.Tuple center, double distance, bool tHemisphere)
 {
     this.bspt        = bspt;
     this.distance    = distance;
     this.distance2   = distance * distance;
     this.center      = center;
     this.tHemisphere = tHemisphere;
     centerValues     = new double[bspt.dimMax];
     for (int dim = bspt.dimMax; --dim >= 0;)
     {
         centerValues[dim] = center.getDimValue(dim);
     }
     stack = new Node[Bspt.stackDepth];
     sp    = 0;
     Bspt.Element ele = bspt.eleRoot;
     while (ele is Node)
     {
         Node node = (Node)ele;
         if (center.getDimValue(node.dim) - distance <= node.splitValue)
         {
             if (sp == Bspt.stackDepth)
             {
                 System.Console.Out.WriteLine("Bspt.EnumerateSphere tree stack overflow");
             }
             stack[sp++] = node;
             ele         = node.eleLE;
         }
         else
         {
             ele = node.eleGE;
         }
     }
     leaf = (Leaf)ele;
     i    = 0;
 }
Beispiel #3
0
 public Node(int dim, int dimMax, Leaf leafLE)
 {
     this.eleLE      = leafLE;
     this.dim        = dim;
     this.dimMax     = dimMax;
     this.splitValue = leafLE.getSplitValue(dim);
     this.eleGE      = new Leaf(leafLE, dim, splitValue);
 }
Beispiel #4
0
 public void addTuple(Bspt.Tuple tuple)
 {
     if (!eleRoot.addTuple(tuple))
     {
         eleRoot = new Node(0, dimMax, (Leaf)eleRoot);
         if (!eleRoot.addTuple(tuple))
         {
             System.Console.Out.WriteLine("Bspt.addTuple() failed");
         }
     }
 }
Beispiel #5
0
 //UPGRADE_NOTE: The equivalent of method 'java.util.Enumeration.nextElement' is not an override method. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1143'"
 public System.Object nextElement()
 {
     if (i == leaf.count)
     {
         //        System.out.println("-->" + stack[sp-1].splitValue);
         Bspt.Element ele = stack[--sp].eleGE;
         while (ele is Node)
         {
             Node node = (Node)ele;
             stack[sp++] = node;
             ele         = node.eleLE;
         }
         leaf = (Leaf)ele;
         i    = 0;
     }
     return(leaf.tuples[i++]);
 }
Beispiel #6
0
 public EnumerateAll(Bspt bspt)
 {
     stack = new Node[Bspt.stackDepth];
     sp    = 0;
     Bspt.Element ele = bspt.eleRoot;
     while (ele is Node)
     {
         Node node = (Node)ele;
         if (sp == Bspt.stackDepth)
         {
             System.Console.Out.WriteLine("Bspt.EnumerateAll tree stack overflow");
         }
         stack[sp++] = node;
         ele         = node.eleLE;
     }
     leaf = (Leaf)ele;
     i    = 0;
 }
Beispiel #7
0
 public bool addTuple(Bspt.Tuple tuple)
 {
     if (tuple.getDimValue(dim) < splitValue)
     {
         if (eleLE.addTuple(tuple))
         {
             return(true);
         }
         eleLE = new Node((dim + 1) % dimMax, dimMax, (Leaf)eleLE);
         return(eleLE.addTuple(tuple));
     }
     if (tuple.getDimValue(dim) > splitValue)
     {
         if (eleGE.addTuple(tuple))
         {
             return(true);
         }
         eleGE = new Node((dim + 1) % dimMax, dimMax, (Leaf)eleGE);
         return(eleGE.addTuple(tuple));
     }
     if (eleLE.LeafWithSpace)
     {
         eleLE.addTuple(tuple);
     }
     else if (eleGE.LeafWithSpace)
     {
         eleGE.addTuple(tuple);
     }
     else if (eleLE is Node)
     {
         eleLE.addTuple(tuple);
     }
     else if (eleGE is Node)
     {
         eleGE.addTuple(tuple);
     }
     else
     {
         eleLE = new Node((dim + 1) % dimMax, dimMax, (Leaf)eleLE);
         return(eleLE.addTuple(tuple));
     }
     return(true);
 }
Beispiel #8
0
 private bool hasMoreElements()
 {
     while (true)
     {
         for (; i < leaf.count; ++i)
         {
             if (isWithin(leaf.tuples[i]))
             {
                 return(true);
             }
         }
         if (sp == 0)
         {
             return(false);
         }
         Bspt.Element ele = stack[--sp];
         while (ele is Node)
         {
             Node node = (Node)ele;
             if (center.getDimValue(node.dim) + distance < node.splitValue)
             {
                 if (sp == 0)
                 {
                     return(false);
                 }
                 ele = stack[--sp];
             }
             else
             {
                 ele = node.eleGE;
                 while (ele is Node)
                 {
                     Node nodeLeft = (Node)ele;
                     stack[sp++] = nodeLeft;
                     ele         = nodeLeft.eleLE;
                 }
             }
         }
         leaf = (Leaf)ele;
         i    = 0;
     }
 }
Beispiel #9
0
 //UPGRADE_NOTE: The equivalent of method 'java.util.Enumeration.hasMoreElements' is not an override method. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1143'"
 public bool hasMoreElements()
 {
     if (i < leaf.count)
     {
         return(true);
     }
     if (sp == 0)
     {
         return(false);
     }
     Bspt.Element ele = stack[--sp];
     while (ele is Node)
     {
         Node node = (Node)ele;
         if (center.getDimValue(node.dim) + distance < node.splitValue)
         {
             if (sp == 0)
             {
                 return(false);
             }
             ele = stack[--sp];
         }
         else
         {
             ele = node.eleGE;
             while (ele is Node)
             {
                 Node nodeLeft = (Node)ele;
                 stack[sp++] = nodeLeft;
                 ele         = nodeLeft.eleLE;
             }
         }
     }
     leaf = (Leaf)ele;
     i    = 0;
     return(true);
 }
Beispiel #10
0
        /*
         * static double distance(int dim, Tuple t1, Tuple t2) {
         * return Math.sqrt(distance2(dim, t1, t2));
         * }
         *
         * static double distance2(int dim, Tuple t1, Tuple t2) {
         * double distance2 = 0.0;
         * while (--dim >= 0) {
         * double distT = t1.getDimValue(dim) - t2.getDimValue(dim);
         * distance2 += distT*distT;
         * }
         * return distance2;
         * }
         */

        public Bspt(int dimMax)
        {
            this.dimMax  = dimMax;
            this.eleRoot = new Leaf();
        }
Beispiel #11
0
 public bool addTuple(Bspt.Tuple tuple)
 {
     if (tuple.getDimValue(dim) < splitValue)
     {
         if (eleLE.addTuple(tuple))
             return true;
         eleLE = new Node((dim + 1) % dimMax, dimMax, (Leaf)eleLE);
         return eleLE.addTuple(tuple);
     }
     if (tuple.getDimValue(dim) > splitValue)
     {
         if (eleGE.addTuple(tuple))
             return true;
         eleGE = new Node((dim + 1) % dimMax, dimMax, (Leaf)eleGE);
         return eleGE.addTuple(tuple);
     }
     if (eleLE.LeafWithSpace)
         eleLE.addTuple(tuple);
     else if (eleGE.LeafWithSpace)
         eleGE.addTuple(tuple);
     else if (eleLE is Node)
         eleLE.addTuple(tuple);
     else if (eleGE is Node)
         eleGE.addTuple(tuple);
     else
     {
         eleLE = new Node((dim + 1) % dimMax, dimMax, (Leaf)eleLE);
         return eleLE.addTuple(tuple);
     }
     return true;
 }
Beispiel #12
0
 public Node(int dim, int dimMax, Leaf leafLE)
 {
     this.eleLE = leafLE;
     this.dim = dim;
     this.dimMax = dimMax;
     this.splitValue = leafLE.getSplitValue(dim);
     this.eleGE = new Leaf(leafLE, dim, splitValue);
 }
Beispiel #13
0
 public void addTuple(Bspt.Tuple tuple)
 {
     if (!eleRoot.addTuple(tuple))
     {
         eleRoot = new Node(0, dimMax, (Leaf)eleRoot);
         if (!eleRoot.addTuple(tuple))
             System.Console.Out.WriteLine("Bspt.addTuple() failed");
     }
 }
Beispiel #14
0
        /*
        static double distance(int dim, Tuple t1, Tuple t2) {
        return Math.sqrt(distance2(dim, t1, t2));
        }
		
        static double distance2(int dim, Tuple t1, Tuple t2) {
        double distance2 = 0.0;
        while (--dim >= 0) {
        double distT = t1.getDimValue(dim) - t2.getDimValue(dim);
        distance2 += distT*distT;
        }
        return distance2;
        }
        */

        public Bspt(int dimMax)
        {
            this.dimMax = dimMax;
            this.eleRoot = new Leaf();
        }