vendor: update reedsolomon package with new perm improvements. (#1422)

master
Harshavardhana 9 years ago
parent 4e34e03dd4
commit a9935f886c
  1. 5
      vendor/github.com/klauspost/reedsolomon/matrix.go
  2. 47
      vendor/github.com/klauspost/reedsolomon/reedsolomon.go
  3. 4
      vendor/vendor.json

@ -178,10 +178,7 @@ func (m matrix) SwapRows(r1, r2 int) error {
// IsSquare will return true if the matrix is square // IsSquare will return true if the matrix is square
// and nil if the matrix is square // and nil if the matrix is square
func (m matrix) IsSquare() bool { func (m matrix) IsSquare() bool {
if len(m) != len(m[0]) { return len(m) == len(m[0])
return false
}
return true
} }
// errSingular is returned if the matrix is singular and cannot be inversed // errSingular is returned if the matrix is singular and cannot be inversed

@ -189,7 +189,7 @@ func (r reedSolomon) Verify(shards [][]byte) (bool, error) {
// number of matrix rows used, is determined by // number of matrix rows used, is determined by
// outputCount, which is the number of outputs to compute. // outputCount, which is the number of outputs to compute.
func (r reedSolomon) codeSomeShards(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) { func (r reedSolomon) codeSomeShards(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
if runtime.GOMAXPROCS(0) > 1 && len(inputs[0]) > splitSize { if runtime.GOMAXPROCS(0) > 1 && len(inputs[0]) > minSplitSize {
r.codeSomeShardsP(matrixRows, inputs, outputs, outputCount, byteCount) r.codeSomeShardsP(matrixRows, inputs, outputs, outputCount, byteCount)
return return
} }
@ -205,24 +205,24 @@ func (r reedSolomon) codeSomeShards(matrixRows, inputs, outputs [][]byte, output
} }
} }
// How many bytes per goroutine. const (
const splitSize = 512 minSplitSize = 512 // min split size per goroutine
maxGoroutines = 50 // max goroutines number for encoding & decoding
)
// Perform the same as codeSomeShards, but split the workload into // Perform the same as codeSomeShards, but split the workload into
// several goroutines. // several goroutines.
func (r reedSolomon) codeSomeShardsP(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) { func (r reedSolomon) codeSomeShardsP(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
var wg sync.WaitGroup var wg sync.WaitGroup
left := byteCount do := byteCount / maxGoroutines
if do < minSplitSize {
do = minSplitSize
}
start := 0 start := 0
for { for start < byteCount {
do := left if start+do > byteCount {
if do > splitSize { do = byteCount - start
do = splitSize
}
if do == 0 {
break
} }
left -= do
wg.Add(1) wg.Add(1)
go func(start, stop int) { go func(start, stop int) {
for c := 0; c < r.DataShards; c++ { for c := 0; c < r.DataShards; c++ {
@ -246,22 +246,19 @@ func (r reedSolomon) codeSomeShardsP(matrixRows, inputs, outputs [][]byte, outpu
// except this will check values and return // except this will check values and return
// as soon as a difference is found. // as soon as a difference is found.
func (r reedSolomon) checkSomeShards(matrixRows, inputs, toCheck [][]byte, outputCount, byteCount int) bool { func (r reedSolomon) checkSomeShards(matrixRows, inputs, toCheck [][]byte, outputCount, byteCount int) bool {
var wg sync.WaitGroup
left := byteCount
start := 0
same := true same := true
var mu sync.RWMutex // For above var mu sync.RWMutex // For above
for { var wg sync.WaitGroup
do := left do := byteCount / maxGoroutines
if do > splitSize { if do < minSplitSize {
do = splitSize do = minSplitSize
} }
if do == 0 { start := 0
break for start < byteCount {
if start+do > byteCount {
do = byteCount - start
} }
left -= do
wg.Add(1) wg.Add(1)
go func(start, do int) { go func(start, do int) {
defer wg.Done() defer wg.Done()
@ -283,7 +280,7 @@ func (r reedSolomon) checkSomeShards(matrixRows, inputs, toCheck [][]byte, outpu
} }
for i, calc := range outputs { for i, calc := range outputs {
if bytes.Compare(calc, toCheck[i][start:start+do]) != 0 { if !bytes.Equal(calc, toCheck[i][start:start+do]) {
mu.Lock() mu.Lock()
same = false same = false
mu.Unlock() mu.Unlock()

@ -64,8 +64,8 @@
}, },
{ {
"path": "github.com/klauspost/reedsolomon", "path": "github.com/klauspost/reedsolomon",
"revision": "d1fe8adc280ef4cd7883943f15a1b5b085a5cced", "revision": "0b630aea2793158b43d0e18f2f50280bfb27c4b4",
"revisionTime": "2016-01-11T14:44:57+01:00" "revisionTime": "2016-04-29T14:00:48-07:00"
}, },
{ {
"path": "github.com/mattn/go-colorable", "path": "github.com/mattn/go-colorable",

Loading…
Cancel
Save