mirror of
https://github.com/logos-storage/nim-poseidon2.git
synced 2026-01-05 23:23:07 +00:00
Remove if statement at compile time
This commit is contained in:
parent
3c8486f73c
commit
aef3b060bb
@ -15,28 +15,28 @@ func merkleRoot(xs: openArray[F], isBottomLayer: static bool) : F =
|
|||||||
let b = high(xs)
|
let b = high(xs)
|
||||||
let m = b-a+1
|
let m = b-a+1
|
||||||
|
|
||||||
if m==1 and not isBottomLayer:
|
when not isBottomLayer:
|
||||||
return xs[a]
|
if m==1:
|
||||||
|
return xs[a]
|
||||||
|
|
||||||
|
let halfn : int = m div 2
|
||||||
|
let n : int = 2*halfn
|
||||||
|
let isOdd : bool = (n != m)
|
||||||
|
|
||||||
|
var ys : seq[F]
|
||||||
|
if not isOdd:
|
||||||
|
ys = newSeq[F](halfn)
|
||||||
else:
|
else:
|
||||||
let halfn : int = m div 2
|
ys = newSeq[F](halfn+1)
|
||||||
let n : int = 2*halfn
|
|
||||||
let isOdd : bool = (n != m)
|
|
||||||
|
|
||||||
var ys : seq[F]
|
for i in 0..<halfn:
|
||||||
if not isOdd:
|
const key = when isBottomLayer: KeyBottomLayer else: KeyNone
|
||||||
ys = newSeq[F](halfn)
|
ys[i] = compress( xs[a+2*i], xs[a+2*i+1], key = key )
|
||||||
else:
|
if isOdd:
|
||||||
ys = newSeq[F](halfn+1)
|
const key = when isBottomLayer: KeyOddAndBottomLayer else: KeyOdd
|
||||||
|
ys[halfn] = compress( xs[n], zero, key = key )
|
||||||
|
|
||||||
for i in 0..<halfn:
|
return merkleRoot(ys, isBottomLayer = false)
|
||||||
const key = when isBottomLayer: KeyBottomLayer else: KeyNone
|
|
||||||
ys[i] = compress( xs[a+2*i], xs[a+2*i+1], key = key )
|
|
||||||
if isOdd:
|
|
||||||
const key = when isBottomLayer: KeyOddAndBottomLayer else: KeyOdd
|
|
||||||
ys[halfn] = compress( xs[n], zero, key = key )
|
|
||||||
|
|
||||||
return merkleRoot(ys, isBottomLayer = false)
|
|
||||||
|
|
||||||
func merkleRoot*(xs: openArray[F]) : F =
|
func merkleRoot*(xs: openArray[F]) : F =
|
||||||
merkleRoot(xs, isBottomLayer = true)
|
merkleRoot(xs, isBottomLayer = true)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user