src/main/java/org/organicdesign/fp/collections/PersistentTreeMap.java
private Node<K,V> add(Node<K,V> t, K key, V val, Box<Node<K,V>> found) {
        if (t == null) {
//            if (val == null)
//                return new Red<>(key);
            return new Red<>(key, val);
        }
        int c = comp.compare(key, t.getKey());
        if (c == 0) {
            found.val = t;
            return null;
        }
        Node<K,V> ins = add(c < 0 ? t.left() : t.right(),
                            key, val, found);
        if (ins == null) //found below
            return null;
        if (c < 0)
            return t.addLeft(ins);
        return t.addRight(ins);
    }
private Node<K,V> add(Node<K,V> t, K key, V val, Box<Node<K,V>> found) {
        if (t == null) {
//            if (val == null)
//                return new Red<>(key);
            return new Red<>(key, val);
        }
        int c = comp.compare(key, t.getKey());
        if (c == 0) {
            found.val = t;
            return null;
        }
        Node<K,V> ins = add(c < 0 ? t.left() : t.right(),
                            key, val, found);
        if (ins == null) //found below
            return null;
        if (c < 0)
            return t.addLeft(ins);
        return t.addRight(ins);
    }
private Node < K , V > add ( Node < K , V > t , K key , V val , Box < Node < K , V > > found ) { if ( t == null ) { //            if (val == null) //                return new Red<>(key); return new Red <> ( key , val ) ; } int c = comp . compare ( key , t . getKey ( ) ) ; if ( c == 0 ) { found . val = t ; return null ; } Node < K , V > ins = add ( c < 0 ? t . left ( ) : t . right ( ) , key , val , found ) ; if ( ins == null ) //found below return null ; if ( c < 0 ) return t . addLeft ( ins ) ; return t . addRight ( ins ) ; }
}
}