Update go dependencies

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-02-19 00:10:16 -03:00
parent f9624cbe46
commit 307bf76454
280 changed files with 54728 additions and 2991 deletions

21
vendor/github.com/yudai/golcs/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Iwasaki Yudai
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.

60
vendor/github.com/yudai/golcs/README.md generated vendored Normal file
View file

@ -0,0 +1,60 @@
# Go Longest Common Subsequence (LCS)
[![GoDoc](https://godoc.org/github.com/yudai/golcs?status.svg)][godoc]
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg)][license]
[godoc]: https://godoc.org/github.com/yudai/golcs
[license]: https://github.com/yudai/golcs/blob/master/LICENSE
A package to calculate [LCS](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem) of slices.
## Usage
```sh
go get github.com/yudai/golcs
```
```go
import " github.com/yudai/golcs"
left = []interface{}{1, 2, 5, 3, 1, 1, 5, 8, 3}
right = []interface{}{1, 2, 3, 3, 4, 4, 5, 1, 6}
lcs := golcs.New(left, right)
lcs.Values() // LCS values => []interface{}{1, 2, 5, 1}
lcs.IndexPairs() // Matched indices => [{Left: 0, Right: 0}, {Left: 1, Right: 1}, {Left: 2, Right: 6}, {Left: 4, Right: 7}]
lcs.Length() // Matched length => 4
lcs.Table() // Memo table
```
All the methods of `Lcs` cache their return values. For example, the memo table is calculated only once and reused when `Values()`, `Length()` and other methods are called.
## FAQ
### How can I give `[]byte` values to `Lcs()` as its arguments?
As `[]interface{}` is incompatible with `[]othertype` like `[]byte`, you need to create a `[]interface{}` slice and copy the values in your `[]byte` slice into it. Unfortunately, Go doesn't provide any mesure to cast a slice into `[]interface{}` with zero cost. Your copy costs O(n).
```go
leftBytes := []byte("TGAGTA")
left = make([]interface{}, len(leftBytes))
for i, v := range leftBytes {
left[i] = v
}
rightBytes := []byte("GATA")
right = make([]interface{}, len(rightBytes))
for i, v := range rightBytes {
right[i] = v
}
lcs.New(left, right)
```
## LICENSE
The MIT license (See `LICENSE` for detail)

195
vendor/github.com/yudai/golcs/golcs.go generated vendored Normal file
View file

@ -0,0 +1,195 @@
// package lcs provides functions to calculate Longest Common Subsequence (LCS)
// values from two arbitrary arrays.
package lcs
import (
"context"
"reflect"
)
// Lcs is the interface to calculate the LCS of two arrays.
type Lcs interface {
// Values calculates the LCS value of the two arrays.
Values() (values []interface{})
// ValueContext is a context aware version of Values()
ValuesContext(ctx context.Context) (values []interface{}, err error)
// IndexPairs calculates paris of indices which have the same value in LCS.
IndexPairs() (pairs []IndexPair)
// IndexPairsContext is a context aware version of IndexPairs()
IndexPairsContext(ctx context.Context) (pairs []IndexPair, err error)
// Length calculates the length of the LCS.
Length() (length int)
// LengthContext is a context aware version of Length()
LengthContext(ctx context.Context) (length int, err error)
// Left returns one of the two arrays to be compared.
Left() (leftValues []interface{})
// Right returns the other of the two arrays to be compared.
Right() (righttValues []interface{})
}
// IndexPair represents an pair of indeices in the Left and Right arrays found in the LCS value.
type IndexPair struct {
Left int
Right int
}
type lcs struct {
left []interface{}
right []interface{}
/* for caching */
table [][]int
indexPairs []IndexPair
values []interface{}
}
// New creates a new LCS calculator from two arrays.
func New(left, right []interface{}) Lcs {
return &lcs{
left: left,
right: right,
table: nil,
indexPairs: nil,
values: nil,
}
}
// Table implements Lcs.Table()
func (lcs *lcs) Table() (table [][]int) {
table, _ = lcs.TableContext(context.Background())
return table
}
// Table implements Lcs.TableContext()
func (lcs *lcs) TableContext(ctx context.Context) (table [][]int, err error) {
if lcs.table != nil {
return lcs.table, nil
}
sizeX := len(lcs.left) + 1
sizeY := len(lcs.right) + 1
table = make([][]int, sizeX)
for x := 0; x < sizeX; x++ {
table[x] = make([]int, sizeY)
}
for y := 1; y < sizeY; y++ {
select { // check in each y to save some time
case <-ctx.Done():
return nil, ctx.Err()
default:
// nop
}
for x := 1; x < sizeX; x++ {
increment := 0
if reflect.DeepEqual(lcs.left[x-1], lcs.right[y-1]) {
increment = 1
}
table[x][y] = max(table[x-1][y-1]+increment, table[x-1][y], table[x][y-1])
}
}
lcs.table = table
return table, nil
}
// Table implements Lcs.Length()
func (lcs *lcs) Length() (length int) {
length, _ = lcs.LengthContext(context.Background())
return length
}
// Table implements Lcs.LengthContext()
func (lcs *lcs) LengthContext(ctx context.Context) (length int, err error) {
table, err := lcs.TableContext(ctx)
if err != nil {
return 0, err
}
return table[len(lcs.left)][len(lcs.right)], nil
}
// Table implements Lcs.IndexPairs()
func (lcs *lcs) IndexPairs() (pairs []IndexPair) {
pairs, _ = lcs.IndexPairsContext(context.Background())
return pairs
}
// Table implements Lcs.IndexPairsContext()
func (lcs *lcs) IndexPairsContext(ctx context.Context) (pairs []IndexPair, err error) {
if lcs.indexPairs != nil {
return lcs.indexPairs, nil
}
table, err := lcs.TableContext(ctx)
if err != nil {
return nil, err
}
pairs = make([]IndexPair, table[len(table)-1][len(table[0])-1])
for x, y := len(lcs.left), len(lcs.right); x > 0 && y > 0; {
if reflect.DeepEqual(lcs.left[x-1], lcs.right[y-1]) {
pairs[table[x][y]-1] = IndexPair{Left: x - 1, Right: y - 1}
x--
y--
} else {
if table[x-1][y] >= table[x][y-1] {
x--
} else {
y--
}
}
}
lcs.indexPairs = pairs
return pairs, nil
}
// Table implements Lcs.Values()
func (lcs *lcs) Values() (values []interface{}) {
values, _ = lcs.ValuesContext(context.Background())
return values
}
// Table implements Lcs.ValuesContext()
func (lcs *lcs) ValuesContext(ctx context.Context) (values []interface{}, err error) {
if lcs.values != nil {
return lcs.values, nil
}
pairs, err := lcs.IndexPairsContext(ctx)
if err != nil {
return nil, err
}
values = make([]interface{}, len(pairs))
for i, pair := range pairs {
values[i] = lcs.left[pair.Left]
}
lcs.values = values
return values, nil
}
// Table implements Lcs.Left()
func (lcs *lcs) Left() (leftValues []interface{}) {
leftValues = lcs.left
return
}
// Table implements Lcs.Right()
func (lcs *lcs) Right() (rightValues []interface{}) {
rightValues = lcs.right
return
}
func max(first int, rest ...int) (max int) {
max = first
for _, value := range rest {
if value > max {
max = value
}
}
return
}