Add an error position iterator class
This commit is contained in:
@@ -4,6 +4,9 @@ Created on 2 juil. 2009
|
|||||||
@author: coissac
|
@author: coissac
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
maxword = sizeof(unsigned long int) * 8 /2
|
||||||
|
|
||||||
cdef import from "math.h":
|
cdef import from "math.h":
|
||||||
double ceil(double x)
|
double ceil(double x)
|
||||||
double log(double x)
|
double log(double x)
|
||||||
@@ -216,4 +219,51 @@ cpdef bint matchPattern(unsigned long int word,pattern):
|
|||||||
match|= eq & (eq >> 1) & pattern.t
|
match|= eq & (eq >> 1) & pattern.t
|
||||||
return match == all
|
return match == all
|
||||||
|
|
||||||
|
cdef class ErrorPositionIterator:
|
||||||
|
|
||||||
|
cdef int _wsize
|
||||||
|
cdef int _errors
|
||||||
|
cdef unsigned long int _mask
|
||||||
|
cdef int _errorpos[32]
|
||||||
|
cdef bint _end
|
||||||
|
|
||||||
|
def __init__(self,wordsize,errorcount):
|
||||||
|
self._wsize=wordsize
|
||||||
|
self._errors=errorcount
|
||||||
|
self._mask=0
|
||||||
|
for i in range(errorcount):
|
||||||
|
self._errorpos[i]=i
|
||||||
|
self._end=False
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
cdef unsigned long int rep
|
||||||
|
cdef bint move=False
|
||||||
|
cdef int i
|
||||||
|
if self._end:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
rep = 0
|
||||||
|
for i in range(self._errors):
|
||||||
|
rep |= 1 << self._errorpos[i]
|
||||||
|
print bin2str(rep)
|
||||||
|
|
||||||
|
move=False
|
||||||
|
i=0
|
||||||
|
while (not move):
|
||||||
|
if self._errorpos[i]<self._errorpos[i+1]-1:
|
||||||
|
self._errorpos[i]+=1
|
||||||
|
move=True
|
||||||
|
i=0
|
||||||
|
print "pos %d/%d moved" % (i,self._wsize)
|
||||||
|
else:
|
||||||
|
self._errorpos[i]=i
|
||||||
|
i+=1
|
||||||
|
if i==self._errors-1 and self._errorpos[i]==self._wsize:
|
||||||
|
self._end=True
|
||||||
|
move=True
|
||||||
|
|
||||||
|
return rep
|
||||||
|
|
Reference in New Issue
Block a user