public Builder<V> addAll(Collection<V> add) { if (auto && add instanceof SortedSet && equalComparators(comparator, ((SortedSet) add).comparator())) { // if we're a SortedSet, permit quick order-preserving addition of items // if we collect all duplicates, don't bother as merge will necessarily be more expensive than sorting at end return mergeAll(add, add.size()); } detected = false; if (values.length < count + add.size()) values = Arrays.copyOf(values, max(count + add.size(), count * 2)); for (V v : add) values[count++] = v; return this; }
public Builder<V> addAll(Collection<V> add) { if (auto && add instanceof SortedSet && equalComparators(comparator, ((SortedSet) add).comparator())) { // if we're a SortedSet, permit quick order-preserving addition of items // if we collect all duplicates, don't bother as merge will necessarily be more expensive than sorting at end return mergeAll(add, add.size()); } detected = false; if (values.length < count + add.size()) values = Arrays.copyOf(values, max(count + add.size(), count * 2)); for (V v : add) values[count++] = v; return this; }
public Builder<V> addAll(Collection<V> add) { if (auto && add instanceof SortedSet && equalComparators(comparator, ((SortedSet) add).comparator())) { // if we're a SortedSet, permit quick order-preserving addition of items // if we collect all duplicates, don't bother as merge will necessarily be more expensive than sorting at end return mergeAll(add, add.size()); } detected = false; if (values.length < count + add.size()) values = Arrays.copyOf(values, max(count + add.size(), count * 2)); for (V v : add) values[count++] = v; return this; }
private Builder<V> mergeAll(Iterable<V> add, int addCount) { assert auto; // ensure the existing contents are in order autoEnforce(); int curCount = count; // we make room for curCount * 2 + addCount, so that we can copy the current values to the end // if necessary for continuing the merge, and have the new values directly after the current value range if (values.length < curCount * 2 + addCount) values = Arrays.copyOf(values, max(curCount * 2 + addCount, curCount * 3)); if (add instanceof BTreeSet) { // use btree set's fast toArray method, to append directly ((BTreeSet) add).toArray(values, curCount); } else { // consider calling toArray() and System.arraycopy int i = curCount; for (V v : add) values[i++] = v; } return mergeAll(addCount); }
private Builder<V> mergeAll(Iterable<V> add, int addCount) { assert auto; // ensure the existing contents are in order autoEnforce(); int curCount = count; // we make room for curCount * 2 + addCount, so that we can copy the current values to the end // if necessary for continuing the merge, and have the new values directly after the current value range if (values.length < curCount * 2 + addCount) values = Arrays.copyOf(values, max(curCount * 2 + addCount, curCount * 3)); if (add instanceof BTreeSet) { // use btree set's fast toArray method, to append directly ((BTreeSet) add).toArray(values, curCount); } else { // consider calling toArray() and System.arraycopy int i = curCount; for (V v : add) values[i++] = v; } return mergeAll(addCount); }
private Builder<V> mergeAll(Iterable<V> add, int addCount) { assert auto; // ensure the existing contents are in order autoEnforce(); int curCount = count; // we make room for curCount * 2 + addCount, so that we can copy the current values to the end // if necessary for continuing the merge, and have the new values directly after the current value range if (values.length < curCount * 2 + addCount) values = Arrays.copyOf(values, max(curCount * 2 + addCount, curCount * 3)); if (add instanceof BTreeSet) { // use btree set's fast toArray method, to append directly ((BTreeSet) add).toArray(values, curCount); } else { // consider calling toArray() and System.arraycopy int i = curCount; for (V v : add) values[i++] = v; } return mergeAll(addCount); }
private Builder<V> mergeAll(Iterable<V> add, int addCount) { assert auto; // ensure the existing contents are in order autoEnforce(); int curCount = count; // we make room for curCount * 2 + addCount, so that we can copy the current values to the end // if necessary for continuing the merge, and have the new values directly after the current value range if (values.length < curCount * 2 + addCount) values = Arrays.copyOf(values, max(curCount * 2 + addCount, curCount * 3)); if (add instanceof BTreeSet) { // use btree set's fast toArray method, to append directly ((BTreeSet) add).toArray(values, curCount); } else { // consider calling toArray() and System.arraycopy int i = curCount; for (V v : add) values[i++] = v; } return mergeAll(addCount); }
public Builder<V> addAll(Collection<V> add) { if (auto && add instanceof SortedSet && equalComparators(comparator, ((SortedSet) add).comparator())) { // if we're a SortedSet, permit quick order-preserving addition of items // if we collect all duplicates, don't bother as merge will necessarily be more expensive than sorting at end return mergeAll(add, add.size()); } detected = false; if (values.length < count + add.size()) values = Arrays.copyOf(values, max(count + add.size(), count * 2)); for (V v : add) values[count++] = v; return this; }