Skip to content

Commit

Permalink
improved difficult loop in remove to help cf
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Jan 8, 2024
1 parent cce23a7 commit bc66f2c
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ShareableValuesHashSet implements Iterable<IValue>{
private int modSize;
private int hashMask;

private Entry<IValue>[] data;
private @Nullable Entry<IValue>[] data;

private int threshold;

Expand Down Expand Up @@ -187,15 +187,16 @@ public boolean remove(Object object){
int position = hash & hashMask;

Entry<IValue> currentStartEntry = data[position];
if(currentStartEntry != null){

if (currentStartEntry != null) {
Entry<IValue> entry = currentStartEntry;
do{
if(hash == entry.hash && entry.value.equals(value)){
do {
if (hash == entry.hash && entry.value.equals(value)) {
Entry<IValue> e = data[position];

data[position] = entry.next;
// Reconstruct the other entries (if necessary).
while(e != entry){
while (e != entry && e != null) {
data[position] = new Entry<>(e.hash, e.value, data[position]);

e = e.next;
Expand All @@ -209,7 +210,7 @@ public boolean remove(Object object){
}

entry = entry.next;
}while(entry != null);
} while(entry != null);
}

return false;
Expand Down Expand Up @@ -338,7 +339,7 @@ private static class SetIterator implements Iterator<IValue>{
private @Nullable Entry<IValue> current;
private int index;

public SetIterator(Entry<IValue>[] entries) {
public SetIterator(@Nullable Entry<IValue>[] entries) {
super();

data = entries;
Expand Down

0 comments on commit bc66f2c

Please sign in to comment.