예제 #1
0
        internal static KDNode ins(HyperPoint key, Object val, KDNode t, int lev, int K)
        {
            if (t == null)
            {
                t = new KDNode(key, val);
            }

            else if (key.equals(t.k))
            {
                if (t.deleted)
                {
                    t.deleted = false;
                    t.v       = val;
                }
                else
                {
                    if (t.duplicates == null)
                    {
                        t.duplicates = new List <object>();
                    }
                    t.duplicates.Add(val);
                }
            }

            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);
        }
예제 #2
0
        internal static KDNode srch(HyperPoint 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);
        }