From 4a15a36fee088a58772e97917544db8620cc9ebc Mon Sep 17 00:00:00 2001 From: Franklin Delehelle Date: Tue, 16 Jan 2024 22:07:15 +0100 Subject: [PATCH] fix: LinkedList semantics --- .../container/stacked/list/StackedList.java | 9 +++++---- .../container/stacked/set/StackedSet.java | 16 +++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java index a32b20f791..f6733deaed 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java @@ -51,11 +51,11 @@ public String toString() { @Override public void enter() { - this.lists.push(new CountedList<>()); + this.lists.addFirst(new CountedList<>()); } public void enter(int initialCapacity) { - this.lists.push(new CountedList<>(initialCapacity)); + this.lists.addFirst(new CountedList<>(initialCapacity)); } @Override @@ -63,7 +63,8 @@ public void pop() { if (this.lists.isEmpty()) { throw new RuntimeException("asymmetric pop"); } - this.totalSize -= this.lists.pop().size(); + + this.totalSize -= this.lists.removeFirst().size(); } @Override @@ -117,7 +118,7 @@ public T[] toArray(@NotNull T[] a) { @Override public boolean add(E e) { this.totalSize++; - return this.lists.get(this.lists.size() - 1).add(e); + return this.lists.getFirst().add(e); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java index b3a844e7c9..28c1675774 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java @@ -42,16 +42,22 @@ public class StackedSet implements StackedContainer, @Override public void enter() { - this.sets.push(new HashSet<>()); + this.sets.addLast(new HashSet<>()); } @Override public void pop() { - Set set = this.sets.pop(); + Set 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 !"); + } + }); } }