func (s *DigestSlice) Write(p []byte) (int, error) {
	if len(p)%64 != 0 {
		return 0, errors.New("input must be divisible by 64")
	}
	for i := 0; i < len(p); i += 64 {
		j := i + 64
		d := Digest(p[i:j])
		s.Insert(d)
	}
	return len(p), nil
}
Write implements the io.Writer interface to input the bytes of
a serialized DigestSlice. Write returns an error and does not write any
data if p is not a multiple of 64 in length.
package id
import (
	"bytes"
	"errors"
	"fmt"
	"sort"
)
type DigestSlice []Digest
func (ds *DigestSlice) Insert(d Digest) int {
	s := *ds
	if d == nil {
		return -1
	}
	i := s.Index(d)
	if i < len(s) && bytes.Compare(s[i], d) == 0 {
		return -(i + 1)
	}
	s = append(s, nil)
	copy(s[i+1:], s[i:])
	s[i] = d
	*ds = s
	return i
}
func (ds *DigestSlice) Digest() Digest {
	s := *ds
	if len(s) == 0 {
		return nil
	}
	list := make([]Digest, len(s))
	copy(list, s)
	for len(list) > 1 {
		odd := oddIndex(len(list))
		prev := list
		list = list[:0]
		for i := 0; i < len(prev)-1; i += 2 {
			list = append(list, prev[i].Sum(prev[i+1]))
		}
		if odd >= 0 {
			list = append(list, prev[odd])
		}
	}
	return list[0]
}
func (ds *DigestSlice) Index(x Digest) int {
	s := *ds
	return sort.Search(len(s), func(i int) bool { return bytes.Compare(s[i], x) >= 0 })
}
func print(s []Digest) {
	for i, dig := range s {
		fmt.Printf("%d: %s\n", i, Digest(dig).ID())
	}
}
func (ds *DigestSlice) Read(p []byte) (int, error) {
	s := *ds
	if len(p) < len(s)*64 {
		return 0, errors.New("buffer too small")
	}
	for i, digest := range s {
		copy(p[i*64:], []byte(digest))
	}
	return len(s) * 64, nil
}