| 332 | } |
| 333 | |
| 334 | Node add(Node t, Object key, Object val, Box found){ |
| 335 | if(t == null) |
| 336 | { |
| 337 | if(comp == RT.DEFAULT_COMPARATOR && !( key == null || (key instanceof Number) || (key instanceof Comparable))) |
| 338 | throw new ClassCastException("Default comparator requires nil, Number, or Comparable: " + key); |
| 339 | if(val == null) |
| 340 | return new Red(key); |
| 341 | return new RedVal(key, val); |
| 342 | } |
| 343 | int c = doCompare(key, t.key); |
| 344 | if(c == 0) |
| 345 | { |
| 346 | found.val = t; |
| 347 | return null; |
| 348 | } |
| 349 | Node ins = c < 0 ? add(t.left(), key, val, found) : add(t.right(), key, val, found); |
| 350 | if(ins == null) //found below |
| 351 | return null; |
| 352 | if(c < 0) |
| 353 | return t.addLeft(ins); |
| 354 | return t.addRight(ins); |
| 355 | } |
| 356 | |
| 357 | Node remove(Node t, Object key, Box found){ |
| 358 | if(t == null) |