Skip to content

Commit

Permalink
refactor: use getters
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Aug 14, 2024
1 parent 5cfa1a6 commit 0043ef2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions certora/applyHarnessFifo.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff -ruN DoubleLinkedList.sol DoubleLinkedList.sol
--- DoubleLinkedList.sol 2024-07-12 09:49:49.899261374 +0200
+++ DoubleLinkedList.sol 2024-07-12 09:53:11.964303440 +0200
--- DoubleLinkedList.sol 2024-08-14 10:10:08.974975205 +0200
+++ DoubleLinkedList.sol 2024-08-14 10:14:10.970436843 +0200
@@ -16,6 +16,8 @@

struct List {
Expand All @@ -15,11 +15,11 @@ diff -ruN DoubleLinkedList.sol DoubleLinkedList.sol
for (; numberOfIterations < maxIterations; numberOfIterations++) {
if (next == address(0) || list.accounts[next].value < value) break;
+ list.insertedAfter = next; // HARNESS
next = list.accounts[next].next;
next = getNext(list, next);
}

if (numberOfIterations == maxIterations) next = address(0);
+ list.insertedBefore = next; // HARNESS

address prev = list.accounts[next].prev;
address prev = getPrev(list, next);
list.accounts[id] = Account(prev, next, value);
10 changes: 5 additions & 5 deletions certora/applyHarnessSimple.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff -ruN DoubleLinkedList.sol DoubleLinkedList.sol
--- DoubleLinkedList.sol 2024-07-12 09:49:49.899261374 +0200
+++ DoubleLinkedList.sol 2024-07-12 09:52:16.333105454 +0200
--- DoubleLinkedList.sol 2024-08-14 10:10:08.974975205 +0200
+++ DoubleLinkedList.sol 2024-08-14 10:13:25.455164370 +0200
@@ -16,6 +16,8 @@

struct List {
Expand All @@ -21,18 +21,18 @@ diff -ruN DoubleLinkedList.sol DoubleLinkedList.sol
if (id == address(0)) revert AddressIsZero();
if (list.accounts[id].value != 0) revert AccountAlreadyInserted();

address next = list.accounts[address(0)].next; // `id` will be inserted before `next`.
address next = getHead(list); // `id` will be inserted before `next`.

- uint256 numberOfIterations;
- for (; numberOfIterations < maxIterations; numberOfIterations++) {
+ for (;;) {
if (next == address(0) || list.accounts[next].value < value) break;
+ list.insertedAfter = next; // HARNESS
next = list.accounts[next].next;
next = getNext(list, next);
}

- if (numberOfIterations == maxIterations) next = address(0);
+ list.insertedBefore = next; // HARNESS

address prev = list.accounts[next].prev;
address prev = getPrev(list, next);
list.accounts[id] = Account(prev, next, value);
6 changes: 3 additions & 3 deletions src/DoubleLinkedList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ library DoubleLinkedList {
if (id == address(0)) revert AddressIsZero();
if (list.accounts[id].value != 0) revert AccountAlreadyInserted();

address next = list.accounts[address(0)].next; // `id` will be inserted before `next`.
address next = getHead(list); // `id` will be inserted before `next`.

uint256 numberOfIterations;
for (; numberOfIterations < maxIterations; numberOfIterations++) {
if (next == address(0) || list.accounts[next].value < value) break;
next = list.accounts[next].next;
next = getNext(list, next);
}

if (numberOfIterations == maxIterations) next = address(0);

address prev = list.accounts[next].prev;
address prev = getPrev(list, next);
list.accounts[id] = Account(prev, next, value);
list.accounts[prev].next = id;
list.accounts[next].prev = id;
Expand Down

0 comments on commit 0043ef2

Please sign in to comment.