public final int treeSize() { return root == 0 ? 0 : size[root]; }
/** clamps index to [0..treeSize()] and inserts object o *before* the specified index */
- public final void insertNode(int index, Object o) {
+ public final synchronized void insertNode(int index, Object o) {
cached_slot = cached_index = -1;
if (index < 0) index = 0;
if (index > treeSize()) index = treeSize();
}
/** clamps index to [0..treeSize()-1] and replaces the object at that index with object o */
- public final void replaceNode(int index, Object o) {
+ public final synchronized void replaceNode(int index, Object o) {
cached_slot = cached_index = -1;
if (index < 0) index = 0;
if (index > treeSize()) index = treeSize() - 1;
}
/** returns the index of o; runs in O((log n)^2) time unless cache hit */
- public final int indexNode(Object o) {
+ public final synchronized int indexNode(Object o) {
if (cached_slot != -1 && objects[cached_slot] == o) return cached_index;
int slot = getSlot(o, o.hashCode() ^ this.hashCode());
}
/** returns the object at index; runs in O(log n) time unless cache hit */
- public final Object getNode(int index) {
+ public final synchronized Object getNode(int index) {
if (index == cached_index) return objects[cached_slot];
if (cached_index != -1) {
}
/** deletes the object at index, returning the deleted object */
- public final Object deleteNode(int index) {
+ public final synchronized Object deleteNode(int index) {
cached_slot = cached_index = -1;
int del = delete(index, root, 0);
left[del] = right[del] = size[del] = 0;