add hashUnordered that uses a walk method and hashes all elements

This commit is contained in:
Brendan Hansknecht 2022-10-12 12:10:53 -07:00
parent f398bb1eff
commit 7a8dee888d
No known key found for this signature in database
GPG key ID: 0EA784685083E75B

View file

@ -81,3 +81,23 @@ hashStrBytes = \hasher, s ->
hashList = \hasher, lst ->
List.walk lst hasher \accumHasher, elem ->
hash accumHasher elem
hashUnordered = \hasher, container, walk ->
walk
container
0
(\accum, elem ->
x =
hasher
|> new
|> hash elem
|> complete
nextAccum = Num.addWrap accum x
if nextAccum < accum then
# we dont want to lose a bit of entropy on overflow, so add it back in.
Num.addWrap nextAccum 1
else
nextAccum
)
|> \accum -> addU64 hasher accum