Update go dependencies
This commit is contained in:
parent
432f534383
commit
f4a4daed84
1299 changed files with 71186 additions and 91183 deletions
19
vendor/github.com/ncabatoff/go-seq/.travis.yml
generated
vendored
Normal file
19
vendor/github.com/ncabatoff/go-seq/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
sudo: false
|
||||
language: go
|
||||
before_install:
|
||||
- go get github.com/mattn/goveralls
|
||||
matrix:
|
||||
include:
|
||||
- go: 1.6.x
|
||||
script: go test -v -race ./...
|
||||
- go: 1.x
|
||||
script:
|
||||
- diff -u <(echo -n) <(gofmt -d .)
|
||||
- go install -v ./...
|
||||
- go vet -v ./...
|
||||
- $GOPATH/bin/goveralls -v -race -service=travis-ci
|
||||
- go: master
|
||||
script: go test -v -race ./...
|
||||
allow_failures:
|
||||
- go: master
|
||||
fast_finish: true
|
||||
21
vendor/github.com/ncabatoff/go-seq/LICENSE
generated
vendored
Normal file
21
vendor/github.com/ncabatoff/go-seq/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 ncabatoff
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
44
vendor/github.com/ncabatoff/go-seq/README.md
generated
vendored
Normal file
44
vendor/github.com/ncabatoff/go-seq/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Package for ordering of Go values
|
||||
|
||||
[][godoc]
|
||||
[][travis]
|
||||
[](https://coveralls.io/github/ncabatoff/go-seq?branch=master)
|
||||
|
||||
This package is intended to allow ordering (most) values via reflection,
|
||||
much like go-cmp allows comparing values for equality.
|
||||
|
||||
This is helpful when trying to write `Less()` methods for sorting structures.
|
||||
Provided all the types in question are supported, you can simply define it
|
||||
as follows:
|
||||
|
||||
```go
|
||||
import "github.com/ncabatoff/go-seq/seq"
|
||||
|
||||
type (
|
||||
MyType struct {
|
||||
a int
|
||||
b string
|
||||
}
|
||||
MyTypeSlice []MyType
|
||||
)
|
||||
func (m MyTypeSlice) Less(i, j int) bool { return seq.Compare(m[i], m[j]) < 0 }
|
||||
```
|
||||
|
||||
Noteable unsupported types include the builtin `complex` type, channels,
|
||||
functions, and maps with non-string keys. Pointers can be ordered if their
|
||||
underlying types are orderable.
|
||||
|
||||
[godoc]: https://godoc.org/github.com/ncabatoff/go-seq/seq
|
||||
[travis]: https://travis-ci.org/ncabatoff/go-seq
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
go get -u github.com/ncabatoff/go-seq/seq
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT - See [LICENSE][license] file
|
||||
|
||||
[license]: https://github.com/ncabatoff/go-seq/blob/master/LICENSE
|
||||
176
vendor/github.com/ncabatoff/go-seq/seq/compare.go
generated
vendored
Normal file
176
vendor/github.com/ncabatoff/go-seq/seq/compare.go
generated
vendored
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
package seq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Compare returns 0 if a and b are equal, -1 if a < b, or 1 if a > b.
|
||||
// Panics if a and b are not of the same type, or are of a type not listed here.
|
||||
// * Bools are compared assuming false < true.
|
||||
// * Strings, integer and float values are compared as Go compares them.
|
||||
// * Two nil pointers are equal; one nil pointer is treated as smaller than a non-nil pointer.
|
||||
// * Non-nil pointers are compared by comparing the values they point to.
|
||||
// * Structures are compared by comparing their fields in order.
|
||||
// * Slices are compared by comparing elements sequentially. If the slices are of different
|
||||
// length and all elements are the same up to the shorter length, the shorter slice is treated as
|
||||
// smaller.
|
||||
// * Maps can only be compared if they have string keys, in which case the ordered list of
|
||||
// keys are first compared as string slices, and if they're equal then the values are compared
|
||||
// sequentially in key order.
|
||||
func Compare(a, b interface{}) int {
|
||||
return compareValue(reflect.ValueOf(a), reflect.ValueOf(b))
|
||||
}
|
||||
|
||||
func boolToInt(b bool) int {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func compareValue(ir1, ir2 reflect.Value) int {
|
||||
var zerovalue reflect.Value
|
||||
r1, r2 := reflect.Indirect(ir1), reflect.Indirect(ir2)
|
||||
|
||||
if r1 == zerovalue {
|
||||
if r2 == zerovalue {
|
||||
return 0
|
||||
}
|
||||
return -1
|
||||
}
|
||||
if r2 == zerovalue {
|
||||
return 1
|
||||
}
|
||||
|
||||
switch r1.Kind() {
|
||||
case reflect.Bool:
|
||||
v1, v2 := boolToInt(r1.Bool()), boolToInt(r2.Bool())
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
v1, v2 := r1.Int(), r2.Int()
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
v1, v2 := r1.Uint(), r2.Uint()
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
case reflect.Float32, reflect.Float64:
|
||||
v1, v2 := r1.Float(), r2.Float()
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
case reflect.Map:
|
||||
return compareMap(r1, r2)
|
||||
case reflect.Struct:
|
||||
return compareStruct(r1, r2)
|
||||
case reflect.Slice:
|
||||
if r1.Type().Elem().Kind() == reflect.Uint8 {
|
||||
// Not using bytes.Compare because that fails on unexported fields:
|
||||
// return bytes.Compare(r1.Interface().([]byte), r2.Interface().([]byte))
|
||||
var s string
|
||||
strtype := reflect.TypeOf(s)
|
||||
v1, v2 := r1.Convert(strtype).String(), r2.Convert(strtype).String()
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return compareSlice(r1, r2)
|
||||
case reflect.String:
|
||||
v1, v2 := r1.String(), r2.String()
|
||||
if v1 < v2 {
|
||||
return -1
|
||||
}
|
||||
if v1 > v2 {
|
||||
return 1
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("don't know how to compare values of type %v", r1.Type()))
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func compareStruct(r1, r2 reflect.Value) int {
|
||||
if r1.Type() != r2.Type() {
|
||||
panic(fmt.Sprintf("s1 and s2 are not of the same type: %v, %v", r1.Type(), r2.Type()))
|
||||
}
|
||||
|
||||
n := r1.NumField()
|
||||
for i := 0; i < n; i++ {
|
||||
c := compareValue(r1.Field(i), r2.Field(i))
|
||||
if c != 0 {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func compareSlice(r1, r2 reflect.Value) int {
|
||||
maxlen := r1.Len()
|
||||
if r2.Len() < maxlen {
|
||||
maxlen = r2.Len()
|
||||
}
|
||||
for i := 0; i < maxlen; i++ {
|
||||
c := compareValue(r1.Index(i), r2.Index(i))
|
||||
if c != 0 {
|
||||
return c
|
||||
}
|
||||
}
|
||||
if r1.Len() > maxlen {
|
||||
return 1
|
||||
}
|
||||
if r2.Len() > maxlen {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func sortedKeys(r1 reflect.Value) []string {
|
||||
keys := make([]string, 0, r1.Len())
|
||||
for _, k := range r1.MapKeys() {
|
||||
keys = append(keys, k.String())
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func compareMap(r1, r2 reflect.Value) int {
|
||||
if r1.Type().Key().Kind() != reflect.String {
|
||||
panic("can only compare maps with keys of type string")
|
||||
}
|
||||
|
||||
s1, s2 := sortedKeys(r1), sortedKeys(r2)
|
||||
c := compareSlice(reflect.ValueOf(s1), reflect.ValueOf(s2))
|
||||
if c != 0 {
|
||||
return c
|
||||
}
|
||||
|
||||
for _, k := range s1 {
|
||||
vk := reflect.ValueOf(k)
|
||||
c := compareValue(r1.MapIndex(vk), r2.MapIndex(vk))
|
||||
if c != 0 {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue