if (index < 0) index = 0;
if (index > treeSize()) index = treeSize();
int arg = allocateSlot(o);
- if (root != 0) { insert(index, arg, root, 0, false, false); return; }
- root = arg;
- left[arg] = 0;
- right[arg] = 0;
- size[root] = 1;
+ if (root != 0) {
+ insert(index, arg, root, 0, false, false);
+ } else {
+ root = arg;
+ left[arg] = 0;
+ right[arg] = 0;
+ size[root] = 1;
+ }
}
/** clamps index to [0..treeSize()-1] and replaces the object at that index with object o */
if (slot == root) {
root = arg;
balance(slot, arg);
+ balance(arg, 0);
} else {
(left[parent] == slot ? left : right)[parent] = arg;
balance(slot, arg);