private ImTreeMapIntToObj AddOrUpdate(int key, object value, bool updateOnly, UpdateValue update) { return(Height == 0 ? // tree is empty (updateOnly ? this : new ImTreeMapIntToObj(key, value, Empty, Empty)) : (key == Key ? // actual update new ImTreeMapIntToObj(key, update == null ? value : update(Value, value), Left, Right) : (key < Key // try update on left or right sub-tree ? With(Left.AddOrUpdate(key, value, updateOnly, update), Right) : With(Left, Right.AddOrUpdate(key, value, updateOnly, update))).KeepBalanced())); }