vendor: Update everything

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4620
This commit is contained in:
Jakob Borg
2017-12-29 11:38:00 +00:00
parent 1296a22069
commit c24bf7ea55
1070 changed files with 294926 additions and 488191 deletions

View File

@@ -14,7 +14,9 @@ const (
Size = 4
)
type digest struct {
// Adler32 is a digest which satisfies the rollinghash.Hash32 interface.
// It implements the adler32 algorithm https://en.wikipedia.org/wiki/Adler-32
type Adler32 struct {
a, b uint32
// window is treated like a circular buffer, where the oldest element
@@ -26,44 +28,43 @@ type digest struct {
vanilla hash.Hash32
}
// Reset resets the Hash to its initial state.
func (d *digest) Reset() {
d.window = d.window[:0] // Reset the size but don't reallocate
// Reset resets the digest to its initial state.
func (d *Adler32) Reset() {
d.window = d.window[:1] // Reset the size but don't reallocate
d.window[0] = 0
d.a = 1
d.b = 0
d.oldest = 0
}
// New returns a new rollinghash.Hash32 computing the rolling Adler-32
// checksum. The window is copied from the last Write(). This window is
// only used to determine which is the oldest element (leaving the
// window). The calls to Roll() do not recompute the whole checksum.
func New() rollinghash.Hash32 {
return &digest{
// New returns a new Adler32 digest
func New() *Adler32 {
return &Adler32{
a: 1,
b: 0,
window: make([]byte, 0),
window: make([]byte, 1, rollinghash.DefaultWindowCap),
oldest: 0,
vanilla: vanilla.New(),
}
}
// Size returns the number of bytes Sum will return.
func (d *digest) Size() int { return Size }
// Size is 4 bytes
func (d *Adler32) Size() int { return Size }
// BlockSize returns the hash's underlying block size.
// The Write method must be able to accept any amount
// of data, but it may operate more efficiently if all
// writes are a multiple of the block size.
func (d *digest) BlockSize() int { return 1 }
// BlockSize is 1 byte
func (d *Adler32) BlockSize() int { return 1 }
// Write (via the embedded io.Writer interface) adds more data to the
// running hash. It never returns an error.
func (d *digest) Write(p []byte) (int, error) {
// Write (re)initializes the rolling window with the input byte slice and
// adds its data to the digest.
func (d *Adler32) Write(p []byte) (int, error) {
// Copy the window, avoiding allocations where possible
if len(d.window) != len(p) {
if cap(d.window) >= len(p) {
d.window = d.window[:len(p)]
l := len(p)
if l == 0 {
l = 1
}
if len(d.window) != l {
if cap(d.window) >= l {
d.window = d.window[:l]
} else {
d.window = make([]byte, len(p))
}
@@ -79,23 +80,20 @@ func (d *digest) Write(p []byte) (int, error) {
return len(d.window), nil
}
func (d *digest) Sum32() uint32 {
// Sum32 returns the hash as a uint32
func (d *Adler32) Sum32() uint32 {
return d.b<<16 | d.a
}
func (d *digest) Sum(b []byte) []byte {
// Sum returns the hash as a byte slice
func (d *Adler32) Sum(b []byte) []byte {
v := d.Sum32()
return append(b, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
}
// Roll updates the checksum of the window from the leaving byte and the
// entering byte. See
// http://stackoverflow.com/questions/40985080/why-does-my-rolling-adler32-checksum-not-work-in-go-modulo-arithmetic
func (d *digest) Roll(b byte) {
if len(d.window) == 0 {
d.window = make([]byte, 1)
d.window[0] = b
}
// Roll updates the checksum of the window from the entering byte. You
// MUST initialize a window with Write() before calling this method.
func (d *Adler32) Roll(b byte) {
// extract the entering/leaving bytes and update the circular buffer.
enter := uint32(b)
leave := uint32(d.window[d.oldest])
@@ -105,7 +103,7 @@ func (d *digest) Roll(b byte) {
d.oldest = 0
}
// compute
// See http://stackoverflow.com/questions/40985080/why-does-my-rolling-adler32-checksum-not-work-in-go-modulo-arithmetic
d.a = (d.a + Mod + enter - leave) % Mod
d.b = (d.b + (d.n*leave/Mod+1)*Mod + d.a - (d.n * leave) - 1) % Mod
}