-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement UsortVerifyMultiplicityBody hint (#368)
* Initial code 'skeleton' for UsortVerifyMultiplicityBody implementation * Read positions from scope manager * Cast positions interface into an array of uint64 * Add test case for empty scopes in ScopeManager * Assign 'current_pos' value in scope * Assign 'last_pos' value in scope * Assign 'next_item_index' value in address/memory * Remove custom message from errors * Make 'Pop' helper function return error if len of slice is 0 * Remove unnecessary tests * Get value of 'last_pos' var from scope to calculate next_item_index value * Change positions slice values to be in reverse order based on hint previous block * Use uint functions instead of int since next_item_index value won't be negative * Refactor tests * Address code review comments * Fix breaking test and get current_pos value from scope * Return custom errors when values cannot be cast * Add missing import after rebase * Rename variables to use camelCase * Cast values to int64
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func Reverse[T any](a []T) { | ||
for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 { | ||
a[i], a[j] = a[j], a[i] | ||
} | ||
} | ||
|
||
func Pop[T any](a *[]T) (T, error) { | ||
if len(*a) == 0 { | ||
var zeroValue T | ||
return zeroValue, fmt.Errorf("cannot pop from an empty slice") | ||
} | ||
|
||
v := (*a)[len(*a)-1] | ||
*a = (*a)[:len(*a)-1] | ||
return v, nil | ||
} |