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"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Technique int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VANDERMONDE = iota
|
VANDERMONDE Technique = iota
|
||||||
CAUCHY
|
CAUCHY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,9 +40,9 @@ const (
|
||||||
|
|
||||||
// EncoderParams is a configuration set for building an encoder. It is created using ValidateParams.
|
// EncoderParams is a configuration set for building an encoder. It is created using ValidateParams.
|
||||||
type EncoderParams struct {
|
type EncoderParams struct {
|
||||||
K,
|
K uint8
|
||||||
M,
|
M uint8
|
||||||
Technique int // cauchy or vandermonde matrix (RS)
|
Technique Technique // cauchy or vandermonde matrix (RS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encoder is an object used to encode and decode data.
|
// 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
|
// 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.
|
// 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 {
|
if k < 1 {
|
||||||
return nil, errors.New("k cannot be zero")
|
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)
|
var block_len = len(block)
|
||||||
|
|
||||||
chunk_size := int(C.minio_calc_chunk_size(e.k, C.uint32_t(block_len)))
|
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
|
pad_len := chunk_len - block_len
|
||||||
|
|
||||||
if pad_len > 0 {
|
if pad_len > 0 {
|
||||||
|
@ -126,7 +128,7 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||||
block = append(block, s...)
|
block = append(block, s...)
|
||||||
}
|
}
|
||||||
|
|
||||||
coded_len := chunk_size * e.p.M
|
coded_len := chunk_size * int(e.p.M)
|
||||||
c := make([]byte, coded_len)
|
c := make([]byte, coded_len)
|
||||||
block = append(block, c...)
|
block = append(block, c...)
|
||||||
|
|
||||||
|
@ -136,12 +138,12 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||||
|
|
||||||
var i int
|
var i int
|
||||||
// Add data blocks to chunks
|
// 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]
|
chunks[i] = block[i*chunk_size : (i+1)*chunk_size]
|
||||||
pointers[i] = &chunks[i][0]
|
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)
|
chunks[i] = make([]byte, chunk_size)
|
||||||
pointers[i] = &chunks[i][0]
|
pointers[i] = &chunks[i][0]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue