Skip to content

Commit

Permalink
fix: ArrayDeque semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Jan 16, 2024
1 parent d6f4682 commit 22b6529
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@ public class StackedSet<E extends ModuleOperation> implements StackedContainer,

@Override
public void enter() {
this.sets.push(new HashSet<>());
this.sets.addLast(new HashSet<>());
}

@Override
public void pop() {
Set<E> set = this.sets.pop();
Set<E> set = this.sets.removeLast();
for (E e : set) {
Integer count = occurrences.get(e);
if (count > 0) occurrences.put(e, count - 1);
else throw new IllegalStateException("asymmetric element removal !");
occurrences.computeIfPresent(
e,
(k, count) -> {
if (count > 0) {
return count - 1;
} else {
throw new IllegalStateException("asymmetric element removal !");
}
});
}
}

Expand Down

0 comments on commit 22b6529

Please sign in to comment.