vendor: Mega update all dependencies

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
Jakob Borg
2017-04-05 14:34:41 +00:00
parent 49c1527724
commit a1bcc15458
1354 changed files with 55066 additions and 797850 deletions

View File

@@ -149,7 +149,7 @@ func BitLenUintptr(n uintptr) int {
// PopCountByte returns population count of n (number of bits set in n).
func PopCountByte(n byte) int {
return int(popcnt[byte(n)])
return int(popcnt[n])
}
// PopCountUint16 returns population count of n (number of bits set in n).

View File

@@ -5,7 +5,9 @@
// Package mathutil provides utilities supplementing the standard 'math' and
// 'math/rand' packages.
//
// Compatibility issues
// Release history and compatibility issues
//
// 2016-10-10: New functions QuadPolyDiscriminant and QuadPolyFactors.
//
// 2013-12-13: The following functions have been REMOVED
//
@@ -89,7 +91,7 @@ func GCDUint16(a, b uint16) uint16 {
return a
}
// GCD returns the greatest common divisor of a and b.
// GCDUint32 returns the greatest common divisor of a and b.
func GCDUint32(a, b uint32) uint32 {
for b != 0 {
a, b = b, a%b
@@ -97,7 +99,7 @@ func GCDUint32(a, b uint32) uint32 {
return a
}
// GCD64 returns the greatest common divisor of a and b.
// GCDUint64 returns the greatest common divisor of a and b.
func GCDUint64(a, b uint64) uint64 {
for b != 0 {
a, b = b, a%b
@@ -257,7 +259,7 @@ func ModPowByte(b, e, m byte) byte {
return byte(r)
}
// ModPowByte computes (b^e)%m. It panics for m == 0 || b == e == 0.
// ModPowUint16 computes (b^e)%m. It panics for m == 0 || b == e == 0.
func ModPowUint16(b, e, m uint16) uint16 {
if b == 0 && e == 0 {
panic(0)
@@ -382,7 +384,7 @@ func MulUint128_64(a, b uint64) (hi, lo uint64) {
mid2 := ahi * blo
c1, lo := AddUint128_64(lo, mid1<<w)
c2, lo := AddUint128_64(lo, mid2<<w)
_, hi = AddUint128_64(ahi*bhi, mid1>>w+mid2>>w+uint64(c1+c2))
_, hi = AddUint128_64(ahi*bhi, mid1>>w+mid2>>w+c1+c2)
return
}

View File

@@ -8,14 +8,14 @@ import (
"sort"
)
// Generate the first permutation of data.
// PermutationFirst generates the first permutation of data.
func PermutationFirst(data sort.Interface) {
sort.Sort(data)
}
// Generate the next permutation of data if possible and return true.
// Return false if there is no more permutation left.
// Based on the algorithm described here:
// PermutationNext generates the next permutation of data if possible and
// return true. Return false if there is no more permutation left. Based on
// the algorithm described here:
// http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order
func PermutationNext(data sort.Interface) bool {
var k, l int

111
vendor/github.com/cznic/mathutil/poly.go generated vendored Normal file
View File

@@ -0,0 +1,111 @@
// Copyright (c) 2016 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil
import (
"fmt"
)
func abs(n int) uint64 {
if n >= 0 {
return uint64(n)
}
return uint64(-n)
}
// QuadPolyDiscriminant returns the discriminant of a quadratic polynomial in
// one variable of the form a*x^2+b*x+c with integer coefficients a, b, c, or
// an error on overflow.
//
// ds is the square of the discriminant. If |ds| is a square number, d is set
// to sqrt(|ds|), otherwise d is < 0.
func QuadPolyDiscriminant(a, b, c int) (ds, d int, _ error) {
if 2*BitLenUint64(abs(b)) > IntBits-1 ||
2+BitLenUint64(abs(a))+BitLenUint64(abs(c)) > IntBits-1 {
return 0, 0, fmt.Errorf("overflow")
}
ds = b*b - 4*a*c
s := ds
if s < 0 {
s = -s
}
d64 := SqrtUint64(uint64(s))
if d64*d64 != uint64(s) {
return ds, -1, nil
}
return ds, int(d64), nil
}
// PolyFactor describes an irreducible factor of a polynomial in one variable
// with integer coefficients P, Q of the form P*x+Q.
type PolyFactor struct {
P, Q int
}
// QuadPolyFactors returns the content and the irreducible factors of the
// primitive part of a quadratic polynomial in one variable with integer
// coefficients a, b, c of the form a*x^2+b*x+c in integers, or an error on
// overflow.
//
// If the factorization in integers does not exists, the return value is (nil,
// nil).
//
// See also:
// https://en.wikipedia.org/wiki/Factorization_of_polynomials#Primitive_part.E2.80.93content_factorization
func QuadPolyFactors(a, b, c int) (content int, primitivePart []PolyFactor, _ error) {
content = int(GCDUint64(abs(a), GCDUint64(abs(b), abs(c))))
switch {
case content == 0:
content = 1
case content > 0:
if a < 0 || a == 0 && b < 0 {
content = -content
}
}
a /= content
b /= content
c /= content
if a == 0 {
if b == 0 {
return content, []PolyFactor{{0, c}}, nil
}
if b < 0 && c < 0 {
b = -b
c = -c
}
if b < 0 {
b = -b
c = -c
}
return content, []PolyFactor{{b, c}}, nil
}
ds, d, err := QuadPolyDiscriminant(a, b, c)
if err != nil {
return 0, nil, err
}
if ds < 0 || d < 0 {
return 0, nil, nil
}
x1num := -b + d
x1denom := 2 * a
gcd := int(GCDUint64(abs(x1num), abs(x1denom)))
x1num /= gcd
x1denom /= gcd
x2num := -b - d
x2denom := 2 * a
gcd = int(GCDUint64(abs(x2num), abs(x2denom)))
x2num /= gcd
x2denom /= gcd
return content, []PolyFactor{{x1denom, -x1num}, {x2denom, -x2num}}, nil
}