Example #1
0
// int *cauchy_original_coding_matrix(int k, int m, int w);
// int *jerasure_matrix_to_bitmatrix(k, m, w, matrix);
func GenerateCRSBitMatrix(k, m, w int) []int {
	gom := make([]int, 0)

	matrix := C.cauchy_original_coding_matrix(C.int(k), C.int(m), C.int(w))
	if matrix == nil {
		log.Fatal("erasure: cannot make matrix")
	}
	bitmatrix := C.jerasure_matrix_to_bitmatrix(C.int(k), C.int(m), C.int(w), matrix)
	if bitmatrix == nil {
		log.Fatal("erasure: cannot make matrix")
	}
	length := int(k * m * w * w)
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(bitmatrix)),
		Len:  length,
		Cap:  length,
	}
	matrixSlice := *(*[]C.int)(unsafe.Pointer(&hdr))

	for _, e := range matrixSlice {
		gom = append(gom, int(e))
	}

	return gom
}
Example #2
0
// NewCaucheGoodCode returns a type of bitmatrix code with both the
// bitmatrix and schedule initialised.
func NewCauchyGoodCode(k, m, w, packetSize int, bufferSize int64) Coder {
	code := &cauchyGoodCode{bitmatrixCode{code{k, m, w, packetSize, bufferSize}, nil, nil}}
	matrix := C.cauchy_good_general_coding_matrix(C.int(k), C.int(m), C.int(w))
	code.bitmatrix = C.jerasure_matrix_to_bitmatrix(C.int(k), C.int(m), C.int(w), matrix)
	code.schedule = C.jerasure_smart_bitmatrix_to_schedule(C.int(k), C.int(m), C.int(w), code.bitmatrix)
	code.ValidateCode()
	return code
}
Example #3
0
// NewCauchyEncoder creates new CauchyEncoder, initialized with parameters from p
func NewCauchyEncoder(p encoder_params) *CauchyEncoder {
	k := C.int(p.b)
	m := C.int(p.r)
	w := C.int(p.word_size)
	matrix := C.cauchy_good_general_coding_matrix(k, m, w)
	bitmatrix := C.jerasure_matrix_to_bitmatrix(k, m, w, matrix)

	return &CauchyEncoder{
		p:           &p,
		k:           k,
		m:           m,
		w:           w,
		packet_size: C.int(p.packet_size),
		bitmatrix:   bitmatrix,
	}
}