private void addIfFound(T key, UnifiedSet<T> other) { int index = this.index(key); Object cur = this.table[index]; if (cur == null) { return; } if (cur instanceof ChainedBucket) { this.addIfFoundFromChain((ChainedBucket) cur, key, other); return; } if (this.nonNullTableObjectEquals(cur, key)) { other.add(this.nonSentinel(cur)); } }
private void addIfFound(T key, UnifiedSet<T> other) { int index = this.index(key); Object cur = this.table[index]; if (cur == null) { return; } if (cur instanceof ChainedBucket) { this.addIfFoundFromChain((ChainedBucket) cur, key, other); return; } if (this.nonNullTableObjectEquals(cur, key)) { other.add(this.nonSentinel(cur)); } }
@Override public UnifiedSet<T> with(T element) { this.add(element); return this; }
@Override public UnifiedSet<T> with(T element) { this.add(element); return this; }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int size = in.readInt(); this.loadFactor = in.readFloat(); this.init(Math.max((int) (size / this.loadFactor) + 1, DEFAULT_INITIAL_CAPACITY)); for (int i = 0; i < size; i++) { this.add((T) in.readObject()); } }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int size = in.readInt(); this.loadFactor = in.readFloat(); this.init(Math.max((int) (size / this.loadFactor) + 1, DEFAULT_INITIAL_CAPACITY)); for (int i = 0; i < size; i++) { this.add((T) in.readObject()); } }
private boolean copyChain(ChainedBucket bucket) { boolean changed = false; do { changed |= this.add(this.nonSentinel(bucket.zero)); if (bucket.one == null) { return changed; } changed |= this.add(this.nonSentinel(bucket.one)); if (bucket.two == null) { return changed; } changed |= this.add(this.nonSentinel(bucket.two)); if (bucket.three == null) { return changed; } if (bucket.three instanceof ChainedBucket) { bucket = (ChainedBucket) bucket.three; continue; } changed |= this.add(this.nonSentinel(bucket.three)); return changed; } while (true); }
private boolean copyChain(ChainedBucket bucket) { boolean changed = false; do { changed |= this.add(this.nonSentinel(bucket.zero)); if (bucket.one == null) { return changed; } changed |= this.add(this.nonSentinel(bucket.one)); if (bucket.two == null) { return changed; } changed |= this.add(this.nonSentinel(bucket.two)); if (bucket.three == null) { return changed; } if (bucket.three instanceof ChainedBucket) { bucket = (ChainedBucket) bucket.three; continue; } changed |= this.add(this.nonSentinel(bucket.three)); return changed; } while (true); }
protected boolean copySet(UnifiedSet<?> unifiedset) { //todo: optimize for current size == 0 boolean changed = false; for (int i = 0; i < unifiedset.table.length; i++) { Object cur = unifiedset.table[i]; if (cur instanceof ChainedBucket) { changed |= this.copyChain((ChainedBucket) cur); } else if (cur != null) { changed |= this.add(this.nonSentinel(cur)); } } return changed; }
protected boolean copySet(UnifiedSet<?> unifiedset) { //todo: optimize for current size == 0 boolean changed = false; for (int i = 0; i < unifiedset.table.length; i++) { Object cur = unifiedset.table[i]; if (cur instanceof ChainedBucket) { changed |= this.copyChain((ChainedBucket) cur); } else if (cur != null) { changed |= this.add(this.nonSentinel(cur)); } } return changed; }
@Override public <V> MutableSet<V> collect(BooleanToObjectFunction<? extends V> function) { UnifiedSet<V> target = UnifiedSet.newSet(this.size()); switch (this.state) { case 0: return target; case 1: return target.with(function.valueOf(false)); case 2: return target.with(function.valueOf(true)); case 3: target.add(function.valueOf(false)); target.add(function.valueOf(true)); return target; default: throw new AssertionError("Invalid state"); } }
@Override public <V> MutableSet<V> collect(BooleanToObjectFunction<? extends V> function) { UnifiedSet<V> target = UnifiedSet.newSet(this.size()); switch (this.state) { case 0: return target; case 1: return target.with(function.valueOf(false)); case 2: return target.with(function.valueOf(true)); case 3: target.add(function.valueOf(false)); target.add(function.valueOf(true)); return target; default: throw new AssertionError("Invalid state"); } }
@Override public boolean addAllIterable(Iterable<? extends T> iterable) { if (iterable instanceof UnifiedSet) { return this.copySet((UnifiedSet<?>) iterable); } int size = Iterate.sizeOf(iterable); this.ensureCapacity(size); int oldSize = this.size(); if (iterable instanceof List && iterable instanceof RandomAccess) { List<T> list = (List<T>) iterable; for (int i = 0; i < size; i++) { this.add(list.get(i)); } } else { Iterate.forEachWith(iterable, Procedures2.addToCollection(), this); } return this.size() != oldSize; }
@Override public boolean addAllIterable(Iterable<? extends T> iterable) { if (iterable instanceof UnifiedSet) { return this.copySet((UnifiedSet<?>) iterable); } int size = Iterate.sizeOf(iterable); this.ensureCapacity(size); int oldSize = this.size(); if (iterable instanceof List && iterable instanceof RandomAccess) { List<T> list = (List<T>) iterable; for (int i = 0; i < size; i++) { this.add(list.get(i)); } } else { Iterate.forEachWith(iterable, Procedures2.addToCollection(), this); } return this.size() != oldSize; }