mirror of
https://github.com/minio/minio.git
synced 2025-01-12 23:43:22 -05:00
Merge pull request #233 from harshavardhana/pr_out_make_k_m_to_be_uint8_and_technique_becomes_its_own_type
This commit is contained in:
commit
33601ff567
@ -26,8 +26,10 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Technique int
|
||||
|
||||
const (
|
||||
VANDERMONDE = iota
|
||||
VANDERMONDE Technique = iota
|
||||
CAUCHY
|
||||
)
|
||||
|
||||
@ -38,9 +40,9 @@ const (
|
||||
|
||||
// EncoderParams is a configuration set for building an encoder. It is created using ValidateParams.
|
||||
type EncoderParams struct {
|
||||
K,
|
||||
M,
|
||||
Technique int // cauchy or vandermonde matrix (RS)
|
||||
K uint8
|
||||
M uint8
|
||||
Technique Technique // cauchy or vandermonde matrix (RS)
|
||||
}
|
||||
|
||||
// Encoder is an object used to encode and decode data.
|
||||
@ -59,7 +61,7 @@ type Encoder struct {
|
||||
// k and m represent the matrix size, which corresponds to the protection level
|
||||
// technique is the matrix type. Valid inputs are CAUCHY (recommended) or VANDERMONDE.
|
||||
//
|
||||
func ParseEncoderParams(k, m, technique int) (*EncoderParams, error) {
|
||||
func ParseEncoderParams(k, m uint8, technique Technique) (*EncoderParams, error) {
|
||||
if k < 1 {
|
||||
return nil, errors.New("k cannot be zero")
|
||||
}
|
||||
@ -117,7 +119,7 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||
var block_len = len(block)
|
||||
|
||||
chunk_size := int(C.minio_calc_chunk_size(e.k, C.uint32_t(block_len)))
|
||||
chunk_len := chunk_size * e.p.K
|
||||
chunk_len := chunk_size * int(e.p.K)
|
||||
pad_len := chunk_len - block_len
|
||||
|
||||
if pad_len > 0 {
|
||||
@ -126,7 +128,7 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||
block = append(block, s...)
|
||||
}
|
||||
|
||||
coded_len := chunk_size * e.p.M
|
||||
coded_len := chunk_size * int(e.p.M)
|
||||
c := make([]byte, coded_len)
|
||||
block = append(block, c...)
|
||||
|
||||
@ -136,12 +138,12 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||
|
||||
var i int
|
||||
// Add data blocks to chunks
|
||||
for i = 0; i < e.p.K; i++ {
|
||||
for i = 0; i < int(e.p.K); i++ {
|
||||
chunks[i] = block[i*chunk_size : (i+1)*chunk_size]
|
||||
pointers[i] = &chunks[i][0]
|
||||
}
|
||||
|
||||
for i = e.p.K; i < (e.p.K + e.p.M); i++ {
|
||||
for i = int(e.p.K); i < int(e.p.K+e.p.M); i++ {
|
||||
chunks[i] = make([]byte, chunk_size)
|
||||
pointers[i] = &chunks[i][0]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user