@Override public T getFirst() { for (int i = 0; i < this.table.length; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { return this.nonSentinel(((ChainedBucket) cur).zero); } if (cur != null) { return this.nonSentinel(cur); } } return null; }
@Override public T getFirst() { for (int i = 0; i < this.table.length; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { return this.nonSentinel(((ChainedBucket) cur).zero); } if (cur != null) { return this.nonSentinel(cur); } } return null; }
private T getLast(ChainedBucket bucket) { while (bucket.three instanceof ChainedBucket) { bucket = (ChainedBucket) bucket.three; } if (bucket.three != null) { return this.nonSentinel(bucket.three); } if (bucket.two != null) { return this.nonSentinel(bucket.two); } if (bucket.one != null) { return this.nonSentinel(bucket.one); } assert bucket.zero != null; return this.nonSentinel(bucket.zero); }
@Override public T getLast() { for (int i = this.table.length - 1; i >= 0; i--) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { return this.getLast((ChainedBucket) cur); } if (cur != null) { return this.nonSentinel(cur); } } return null; }
@Override public T getLast() { for (int i = this.table.length - 1; i >= 0; i--) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { return this.getLast((ChainedBucket) cur); } if (cur != null) { return this.nonSentinel(cur); } } return null; }
protected void each(Procedure<? super T> procedure, int start, int end) { for (int i = start; i < end; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { this.chainedForEach((ChainedBucket) cur, procedure); } else if (cur != null) { procedure.value(this.nonSentinel(cur)); } } }
@Override public <P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter) { for (int i = 0; i < this.table.length; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { this.chainedForEachWith((ChainedBucket) cur, procedure, parameter); } else if (cur != null) { procedure.value(this.nonSentinel(cur), parameter); } } }
protected void each(Procedure<? super T> procedure, int start, int end) { for (int i = start; i < end; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { this.chainedForEach((ChainedBucket) cur, procedure); } else if (cur != null) { procedure.value(this.nonSentinel(cur)); } } }
@Override public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure) { int count = 0; for (int i = 0; i < this.table.length; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { count = this.chainedForEachWithIndex((ChainedBucket) cur, objectIntProcedure, count); } else if (cur != null) { objectIntProcedure.value(this.nonSentinel(cur), count++); } } }
@Override public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure) { int count = 0; for (int i = 0; i < this.table.length; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { count = this.chainedForEachWithIndex((ChainedBucket) cur, objectIntProcedure, count); } else if (cur != null) { objectIntProcedure.value(this.nonSentinel(cur), count++); } } }
@Override public <P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter) { for (int i = 0; i < this.table.length; i++) { Object cur = this.table[i]; if (cur instanceof ChainedBucket) { this.chainedForEachWith((ChainedBucket) cur, procedure, parameter); } else if (cur != null) { procedure.value(this.nonSentinel(cur), parameter); } } }
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 void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.size()); out.writeFloat(this.loadFactor); for (int i = 0; i < this.table.length; i++) { Object o = this.table[i]; if (o != null) { if (o instanceof ChainedBucket) { this.writeExternalChain(out, (ChainedBucket) o); } else { out.writeObject(this.nonSentinel(o)); } } } }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.size()); out.writeFloat(this.loadFactor); for (int i = 0; i < this.table.length; i++) { Object o = this.table[i]; if (o != null) { if (o instanceof ChainedBucket) { this.writeExternalChain(out, (ChainedBucket) o); } else { out.writeObject(this.nonSentinel(o)); } } } }
@Override public void batchForEach(Procedure<? super T> procedure, int sectionIndex, int sectionCount) { Object[] set = this.table; int sectionSize = set.length / sectionCount; int start = sectionSize * sectionIndex; int end = sectionIndex == sectionCount - 1 ? set.length : start + sectionSize; for (int i = start; i < end; i++) { Object cur = set[i]; if (cur != null) { if (cur instanceof ChainedBucket) { this.chainedForEach((ChainedBucket) cur, procedure); } else { procedure.value(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)); } }
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 T put(T key) { int index = this.index(key); Object cur = this.table[index]; if (cur == null) { this.table[index] = UnifiedSet.toSentinelIfNull(key); if (++this.occupied > this.maxSize) { this.rehash(); } return key; } if (cur instanceof ChainedBucket || !this.nonNullTableObjectEquals(cur, key)) { return this.chainedPut(key, index); } return this.nonSentinel(cur); }
@Override public T put(T key) { int index = this.index(key); Object cur = this.table[index]; if (cur == null) { this.table[index] = UnifiedSet.toSentinelIfNull(key); if (++this.occupied > this.maxSize) { this.rehash(); } return key; } if (cur instanceof ChainedBucket || !this.nonNullTableObjectEquals(cur, key)) { return this.chainedPut(key, index); } return this.nonSentinel(cur); }