Skip to content

Commit

Permalink
Fix AbstractBucket partitioning (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jan 24, 2022
1 parent 694f4a0 commit 69ba794
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions helper/src/main/java/me/lucko/helper/bucket/AbstractBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.google.common.collect.ImmutableList;

import me.lucko.helper.bucket.partitioning.PartitioningStrategy;
import me.lucko.helper.utils.ImmutableCollectors;

import java.util.AbstractSet;
import java.util.Collection;
Expand Down Expand Up @@ -82,14 +81,19 @@ protected AbstractBucket(int size, PartitioningStrategy<E> strategy) {
this.size = size;
this.content = createSet();

//noinspection unchecked
Set<E>[] objs = new Set[size];
ImmutableList.Builder<Set<E>> sets = ImmutableList.builder();
ImmutableList.Builder<BucketPartition<E>> views = ImmutableList.builder();

for (int i = 0; i < size; i++) {
objs[i] = createSet();
Set<E> set = createSet();
sets.add(set);

SetView view = new SetView(set, i);
views.add(view);
}

this.partitions = ImmutableList.copyOf(objs);
this.partitionView = this.partitions.stream().map(SetView::new).collect(ImmutableCollectors.toList());
this.partitions = sets.build();
this.partitionView = views.build();
this.partitionCycle = Cycle.of(this.partitionView);
}

Expand Down Expand Up @@ -235,9 +239,9 @@ private final class SetView extends AbstractSet<E> implements BucketPartition<E>
private final Set<E> backing;
private final int index;

private SetView(Set<E> backing) {
private SetView(Set<E> backing, int index) {
this.backing = backing;
this.index = AbstractBucket.this.partitions.indexOf(backing);
this.index = index;
}

@Override
Expand Down

0 comments on commit 69ba794

Please sign in to comment.