mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
merge changes and fix wrong type -- k and m need more than 8 bits (because they are the count rather than the index, i.e. they are 1-indexed)
This commit is contained in:
parent
1b23579715
commit
c8b1eec75a
@ -71,8 +71,8 @@ typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
/* expose these */
|
||||
int kk;
|
||||
int mm;
|
||||
unsigned short kk;
|
||||
unsigned short mm;
|
||||
|
||||
/* internal */
|
||||
fec_t* fec_matrix;
|
||||
@ -111,16 +111,16 @@ Encoder_init(Encoder *self, PyObject *args, PyObject *kwdict) {
|
||||
py_raise_fec_error("Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm);
|
||||
return -1;
|
||||
}
|
||||
if (self->mm > 255) {
|
||||
py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 255, but it was %d", self->mm);
|
||||
if (inm > 256) {
|
||||
py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 256, but it was %d", self->mm);
|
||||
return -1;
|
||||
}
|
||||
if (ink > inm) {
|
||||
py_raise_fec_error("Precondition violation: first argument is required to be less than or equal to the second argument, but they were %d and %d respectively", ink, inm);
|
||||
return -1;
|
||||
}
|
||||
self->kk = (unsigned char)ink;
|
||||
self->mm = (unsigned char)inm;
|
||||
self->kk = (unsigned short)ink;
|
||||
self->mm = (unsigned short)inm;
|
||||
self->fec_matrix = fec_new(self->kk, self->mm);
|
||||
|
||||
return 0;
|
||||
@ -326,8 +326,8 @@ typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
/* expose these */
|
||||
int kk;
|
||||
int mm;
|
||||
unsigned short kk;
|
||||
unsigned short mm;
|
||||
|
||||
/* internal */
|
||||
fec_t* fec_matrix;
|
||||
@ -367,16 +367,16 @@ Decoder_init(Encoder *self, PyObject *args, PyObject *kwdict) {
|
||||
py_raise_fec_error("Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm);
|
||||
return -1;
|
||||
}
|
||||
if (self->mm > 255) {
|
||||
py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 255, but it was %d", self->mm);
|
||||
if (inm > 256) {
|
||||
py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 256, but it was %d", self->mm);
|
||||
return -1;
|
||||
}
|
||||
if (ink > inm) {
|
||||
py_raise_fec_error("Precondition violation: first argument is required to be less than or equal to the second argument, but they were %d and %d respectively", ink, inm);
|
||||
return -1;
|
||||
}
|
||||
self->kk = (unsigned char)ink;
|
||||
self->mm = (unsigned char)inm;
|
||||
self->kk = (unsigned short)ink;
|
||||
self->mm = (unsigned short)inm;
|
||||
self->fec_matrix = fec_new(self->kk, self->mm);
|
||||
|
||||
return 0;
|
||||
|
@ -434,14 +434,14 @@ _invert_mat(gf* src, unsigned k) {
|
||||
* p = coefficients of the matrix (p_i)
|
||||
* q = values of the polynomial (known)
|
||||
*/
|
||||
int
|
||||
_invert_vdm (gf * src, int k) {
|
||||
int i, j, row, col;
|
||||
void
|
||||
_invert_vdm (gf* src, unsigned k) {
|
||||
unsigned i, j, row, col;
|
||||
gf *b, *c, *p;
|
||||
gf t, xx;
|
||||
|
||||
if (k == 1) /* degenerate case, matrix must be p^0 = 1 */
|
||||
return 0;
|
||||
return;
|
||||
/*
|
||||
* c holds the coefficient of P(x) = Prod (x - p_i), i=0..k-1
|
||||
* b holds the coefficient for the matrix inversion
|
||||
@ -486,7 +486,7 @@ _invert_vdm (gf * src, int k) {
|
||||
free (c);
|
||||
free (b);
|
||||
free (p);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
static int fec_initialized = 0;
|
||||
|
@ -30,6 +30,17 @@ import sys
|
||||
|
||||
import fec
|
||||
|
||||
from base64 import b32encode
|
||||
def ab(x): # debuggery
|
||||
if len(x) >= 3:
|
||||
return "%s:%s" % (len(x), b32encode(x[-3:]),)
|
||||
elif len(x) == 2:
|
||||
return "%s:%s" % (len(x), b32encode(x[-2:]),)
|
||||
elif len(x) == 1:
|
||||
return "%s:%s" % (len(x), b32encode(x[-1:]),)
|
||||
elif len(x) == 0:
|
||||
return "%s:%s" % (len(x), "--empty--",)
|
||||
|
||||
def _h(k, m, ss):
|
||||
# sys.stdout.write("k: %s, m: %s, len(ss): %r, len(ss[0]): %r" % (k, m, len(ss), len(ss[0]),)) ; sys.stdout.flush()
|
||||
encer = fec.Encoder(k, m)
|
||||
@ -47,7 +58,7 @@ def _h(k, m, ss):
|
||||
decoded = decer.decode(blocks, nums)
|
||||
# sys.stdout.write("decoded.\n") ; sys.stdout.flush()
|
||||
assert len(decoded) == len(ss), (len(decoded), len(ss),)
|
||||
assert tuple([str(s) for s in decoded]) == tuple([str(s) for s in ss]), (tuple([str(s) for s in decoded]), tuple([str(s) for s in ss]),)
|
||||
assert tuple([str(s) for s in decoded]) == tuple([str(s) for s in ss]), (tuple([ab(str(s)) for s in decoded]), tuple([ab(str(s)) for s in ss]),)
|
||||
|
||||
def randstr(n):
|
||||
return ''.join(map(chr, map(random.randrange, [0]*n, [256]*n)))
|
||||
|
Loading…
Reference in New Issue
Block a user