Skip to content

Commit be27611

Browse files
committed
docs: fix SplitDigest example and note mixed digests are safe
1 parent 6af0591 commit be27611

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bbloom.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,14 @@ func (bl *Bloom) AddIfNotHasTS(entry []byte) (added bool) {
297297
// Typical usage with a go-cid CID and go-multihash:
298298
//
299299
// dm, _ := multihash.Decode(c.Hash())
300-
// if dm.Code != multihash.IDENTITY && len(dm.Digest) >= 16 {
301-
// h1, h2 := bbloom.SplitDigest(dm.Digest)
302-
// bf.AddHashed(h1, h2)
303-
// }
300+
// h1, h2 := bbloom.SplitDigest(dm.Digest)
301+
// bf.AddHashed(h1, h2)
304302
//
305-
// Identity multihashes (code 0x00) contain raw data, not a crypto digest,
306-
// and must fall back to the SipHash path ([Bloom.Add]).
303+
// Digests from different hash functions (SHA2-256, BLAKE2b-256, etc.) can
304+
// be mixed freely in the same filter -- each produces uniform, independent
305+
// bytes. Identity multihashes (code 0x00) and digests shorter than 16
306+
// bytes cannot use this path; use a separate [Bloom] with [Bloom.Add]
307+
// for those.
307308
func SplitDigest(digest []byte) (h1, h2 uint64) {
308309
_ = digest[15] // bounds check hint
309310
h1 = binary.LittleEndian.Uint64(digest[:8])

0 commit comments

Comments
 (0)