if (parent == 0) return size(left[slot]); // we are on the far left edge
// all nodes after parent and before us are in our left subtree
- return size(left[slot]) + indexNode(objects[parent]) + 1;
+ return size(left[slot]) + (parent <= 0 ? 0 : indexNode(objects[parent])) + 1;
}
/** returns the object at index; runs in O(log n) time unless cache hit */
} else {
int left_childs_rightmost = delete(size(left[slot]) - 1, left[slot], slot);
left[left_childs_rightmost] = left[slot];
- left[left_childs_rightmost] = right[slot];
+ right[left_childs_rightmost] = right[slot];
if (parent == 0) root = left_childs_rightmost;
else (left[parent] == slot ? left : right)[parent] = left_childs_rightmost; // fix parent's pointer
balance(left_childs_rightmost, parent);