Skip to content

Commit

Permalink
fix mergeIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Dec 16, 2024
1 parent cd1d7a3 commit db574a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/groth16/bn254/mpcsetup/phase2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion backend/groth16/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ func (i *MergeIterator) findLeast() {
// Peek returns the next smallest value and the index of the slice it came from
// If the iterator is empty, Peek returns (math.MaxInt, -1)
func (i *MergeIterator) Peek() (value, index int) {
if i.leastIndex == -1 {
return math.MaxInt, -1
}
return i.slices[i.leastIndex][0], i.leastIndex
}

// Next returns the next smallest value and the index of the slice it came from, and advances the iterator
// If the iterator is empty, Next returns (math.MaxInt, -1)
func (i *MergeIterator) Next() (value, index int) {
value, index = i.Peek()
i.findLeast()
i.slices[i.leastIndex] = i.slices[i.leastIndex][1:]
i.findLeast()
return
}

Expand Down

0 comments on commit db574a4

Please sign in to comment.