Example #1
0
            public static KDNode delete(HPoint key, KDNode t, int lev, int K, ref bool deleted)
            {
                if (t == null)
                {
                    return(null);
                }
                if (!t.deleted && key.equals(t.k))
                {
                    t.deleted = true;
                    deleted   = true;
                }
                else if (key.coord[lev] > t.k.coord[lev])
                {
                    t.right = delete(key, t.right, (lev + 1) % K, K, ref deleted);
                }
                else
                {
                    t.left = delete(key, t.left, (lev + 1) % K, K, ref deleted);
                }

                if (!t.deleted || t.left != null || t.right != null)
                {
                    return(t);
                }
                else
                {
                    return(null);
                }
            }
Example #2
0
            // Method ins translated from 352.ins.c of Gonnet & Baeza-Yates
            public static KDNode ins(HPoint key, Object val, KDNode t, int lev, int K)
            {
                if (t == null)
                {
                    t = new KDNode(key, val);
                }

                else if (key.equals(t.k))
                {
                    // "re-insert"
                    if (t.deleted)
                    {
                        t.deleted = false;
                        t.v       = val;
                    }

                    else
                    {
                        throw (new KeyDuplicateException());
                    }
                }

                else if (key.coord[lev] > t.k.coord[lev])
                {
                    t.right = ins(key, val, t.right, (lev + 1) % K, K);
                }
                else
                {
                    t.left = ins(key, val, t.left, (lev + 1) % K, K);
                }

                return(t);
            }
Example #3
0
            // Method srch translated from 352.srch.c of Gonnet & Baeza-Yates
            public static KDNode srch(HPoint key, KDNode t, int K)
            {
                for (int lev = 0; t != null; lev = (lev + 1) % K)
                {
                    if (!t.deleted && key.equals(t.k))
                    {
                        return(t);
                    }
                    else if (key.coord[lev] > t.k.coord[lev])
                    {
                        t = t.right;
                    }
                    else
                    {
                        t = t.left;
                    }
                }

                return(null);
            }