void buildFromSorted(Iterator itr, int size) { modCount++; this.size = size; // nodes at the bottom (unbalanced) level must be red int bottom = 0; for (int ssize = 1; ssize-1 < size; ssize <<= 1) bottom++; this.root = createFromSorted(itr, size, 0, bottom); }
void buildFromSorted(Iterator itr, int size) { modCount++; this.size = size; // nodes at the bottom (unbalanced) level must be red int bottom = 0; for (int ssize = 1; ssize-1 < size; ssize <<= 1) bottom++; this.root = createFromSorted(itr, size, 0, bottom); }
void buildFromSorted(Iterator itr, int size) { modCount++; this.size = size; // nodes at the bottom (unbalanced) level must be red int bottom = 0; for (int ssize = 1; ssize-1 < size; ssize <<= 1) bottom++; this.root = createFromSorted(itr, size, 0, bottom); }
private static Entry createFromSorted(Iterator itr, int size, int level, int bottom) { level++; if (size == 0) return null; int leftSize = (size-1) >> 1; int rightSize = size-1-leftSize; Entry left = createFromSorted(itr, leftSize, level, bottom); Map.Entry orig = (Map.Entry)itr.next(); Entry right = createFromSorted(itr, rightSize, level, bottom); Entry e = new Entry(orig.getKey(), orig.getValue()); if (left != null) { e.left = left; left.parent = e; } if (right != null) { e.right = right; right.parent = e; } if (level == bottom) e.color = Entry.RED; return e; }
private static Entry createFromSorted(Iterator itr, int size, int level, int bottom) { level++; if (size == 0) return null; int leftSize = (size-1) >> 1; int rightSize = size-1-leftSize; Entry left = createFromSorted(itr, leftSize, level, bottom); Map.Entry orig = (Map.Entry)itr.next(); Entry right = createFromSorted(itr, rightSize, level, bottom); Entry e = new Entry(orig.getKey(), orig.getValue()); if (left != null) { e.left = left; left.parent = e; } if (right != null) { e.right = right; right.parent = e; } if (level == bottom) e.color = Entry.RED; return e; }
private static Entry createFromSorted(Iterator itr, int size, int level, int bottom) { level++; if (size == 0) return null; int leftSize = (size-1) >> 1; int rightSize = size-1-leftSize; Entry left = createFromSorted(itr, leftSize, level, bottom); Map.Entry orig = (Map.Entry)itr.next(); Entry right = createFromSorted(itr, rightSize, level, bottom); Entry e = new Entry(orig.getKey(), orig.getValue()); if (left != null) { e.left = left; left.parent = e; } if (right != null) { e.right = right; right.parent = e; } if (level == bottom) e.color = Entry.RED; return e; }