Example #1
0
 protected String toString(int depth) {
   String s = k + "  " + v + (deleted ? "*" : "");
   if (left != null) {
     s = s + "\n" + pad(depth) + "L " + left.toString(depth + 1);
   }
   if (right != null) {
     s = s + "\n" + pad(depth) + "R " + right.toString(depth + 1);
   }
   return s;
 }
Example #2
0
  // Method ins translated from 352.ins.c of Gonnet & Baeza-Yates
  protected static KDNode ins(HPoint key, Object val, KDNode t, int lev, int K)
      throws KeyDuplicateException {

    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;
  }