-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'arith-dev' into 1189-fix-ramtolimbsinglesource-doesnt-r…
…ead-tbo
- Loading branch information
Showing
44 changed files
with
375 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...c/main/java/net/consensys/linea/zktracer/container/stacked/ModuleOperationStackedSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.zktracer.container.stacked; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
import com.google.common.base.Preconditions; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import net.consensys.linea.zktracer.container.ModuleOperation; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Implements a system of pseudo-stacked squashed sets where {@link | ||
* ModuleOperationStackedSet#operationsCommitedToTheConflation()} represents the set of all | ||
* operations since the beginning of the conflation and {@link | ||
* ModuleOperationStackedSet#operationsInTransaction()} represents the operations added by the last | ||
* transaction. We can pop only the operations added by last transaction. The line counting is done | ||
* by a separate {@link CountOnlyOperation}. | ||
* | ||
* @param <E> the type of elements stored in the set | ||
*/ | ||
@Accessors(fluent = true) | ||
public class ModuleOperationStackedSet<E extends ModuleOperation> extends StackedSet<E> { | ||
private static final Logger log = LoggerFactory.getLogger(ModuleOperationStackedSet.class); | ||
private final CountOnlyOperation lineCounter = new CountOnlyOperation(); | ||
@Getter private boolean conflationFinished = false; | ||
|
||
public ModuleOperationStackedSet() { | ||
super(); | ||
} | ||
|
||
/** Prefer this constructor as we preallocate more needed memory */ | ||
public ModuleOperationStackedSet( | ||
final int expectedConflationNumberOperations, final int expectedTransactionNumberOperations) { | ||
super(expectedConflationNumberOperations, expectedTransactionNumberOperations); | ||
} | ||
|
||
/** | ||
* Upon entering a new transaction, the set of operations generated by the previous transaction | ||
* {@link ModuleOperationStackedSet#operationsInTransaction()} (which is empty if no such | ||
* transaction exists) is added to the set of committed operations {@link | ||
* ModuleOperationStackedSet#operationsCommitedToTheConflation()}. {@link | ||
* ModuleOperationStackedSet#operationsInTransaction()} is further reset to be empty. | ||
*/ | ||
public void enter() { | ||
super.enter(); | ||
lineCounter.enter(); | ||
} | ||
|
||
public void pop() { | ||
super.pop(); | ||
lineCounter.pop(); | ||
} | ||
|
||
public int size() { | ||
return operationsInTransaction().size() + operationsCommitedToTheConflation().size(); | ||
} | ||
|
||
public int lineCount() { | ||
return lineCounter.lineCount(); | ||
} | ||
|
||
public Set<E> getAll() { | ||
Preconditions.checkState(conflationFinished, "Conflation not finished"); | ||
return operationsCommitedToTheConflation(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return size() == 0; | ||
} | ||
|
||
public boolean contains(Object o) { | ||
return operationsInTransaction().contains(o) || operationsCommitedToTheConflation().contains(o); | ||
} | ||
|
||
public boolean add(E e) { | ||
if (!operationsCommitedToTheConflation().contains(e)) { | ||
final boolean isNew = operationsInTransaction().add(e); | ||
if (isNew) { | ||
lineCounter.add(e.lineCount()); | ||
} | ||
return isNew; | ||
} else { | ||
log.trace( | ||
"Operation of type {} was already in operationsCommitedToTheConflation hashset, reference is ", | ||
e.getClass().getName(), | ||
e); | ||
} | ||
return false; | ||
} | ||
|
||
public boolean containsAll(@NotNull Collection<?> c) { | ||
for (var x : c) { | ||
if (!contains(x)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public boolean addAll(@NotNull Collection<? extends E> c) { | ||
boolean r = false; | ||
for (var x : c) { | ||
r |= add(x); | ||
} | ||
return r; | ||
} | ||
|
||
public void clear() { | ||
operationsCommitedToTheConflation().clear(); | ||
operationsInTransaction().clear(); | ||
lineCounter.clear(); | ||
} | ||
|
||
public void finishConflation() { | ||
conflationFinished = true; | ||
operationsCommitedToTheConflation().addAll(operationsInTransaction()); | ||
operationsInTransaction().clear(); | ||
lineCounter.enter(); // this is not mandatory but it is more consistent | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
...n/src/main/java/net/consensys/linea/zktracer/container/stacked/NoLineCountStackedSet.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.