Skip to content

Commit

Permalink
HashFile and friends are available in parallel.go
Browse files Browse the repository at this point in the history
  Tests are in parallel_test.go.

  The defaults give about a 6x speed up
  when hashing large files on my box.
  • Loading branch information
Jason E. Aten, Ph.D. committed Feb 2, 2025
1 parent 4f5562c commit 51f61af
Show file tree
Hide file tree
Showing 3 changed files with 865 additions and 2 deletions.
13 changes: 11 additions & 2 deletions blake3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ type Hasher struct {
size int // output size, for Sum

// log(n) set of Merkle subtree roots, at most one per height.
stack [64 - (guts.MaxSIMD + 10)][8]uint32 // 10 = log2(guts.ChunkSize)
counter uint64 // number of buffers hashed; also serves as a bit vector indicating which stack elems are occupied
// 4 = log2(guts.MaxSIMD)
// 10 = log2(guts.ChunkSize)
stack [64 - (4 + 10)][8]uint32
counter uint64 // number of buffers hashed; also serves as a bit vector indicating which stack elems are occupied

buf [guts.MaxSIMD * guts.ChunkSize]byte
buflen int
}

func init() {
if guts.MaxSIMD != 16 {
panic("since guts.MaxSIMD is no longer 16, fix the " +
"log2(MaxSIMD) hard-coded above in the Hasher.stack size")
}
}

func (h *Hasher) hasSubtreeAtHeight(i int) bool {
return h.counter&(1<<i) != 0
}
Expand Down
Loading

0 comments on commit 51f61af

Please sign in to comment.