add an internal implementation of bin function (bin2str) that is appeared
only in python 2.6
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,26 @@ Created on 2 juil. 2009
|
||||
@author: coissac
|
||||
'''
|
||||
|
||||
cdef import from "math.h":
|
||||
double ceil(double x)
|
||||
double log(double x)
|
||||
|
||||
cdef int binarywordsize(unsigned long long int x):
|
||||
return <int>ceil(log(x)/log(2))
|
||||
|
||||
cpdef str bin2str(unsigned long long int x):
|
||||
cdef str rep=''
|
||||
cdef unsigned long long int i
|
||||
cdef int ws = binarywordsize(x)
|
||||
|
||||
for i in range(ws):
|
||||
if x & (1 << i):
|
||||
rep = '1' + rep
|
||||
else:
|
||||
rep = '0' + rep
|
||||
return rep
|
||||
|
||||
|
||||
|
||||
cdef class WordPattern :
|
||||
cdef public unsigned long long int a
|
||||
@@ -22,10 +42,10 @@ cdef class WordPattern :
|
||||
self.t=t
|
||||
|
||||
def __str__(self):
|
||||
return b"(a:%s,c:%s,g:%s,t:%s)" % (bin(self.a),
|
||||
bin(self.c),
|
||||
bin(self.g),
|
||||
bin(self.t))
|
||||
return b"(a:%s,c:%s,g:%s,t:%s)" % (bin2str(self.a),
|
||||
bin2str(self.c),
|
||||
bin2str(self.g),
|
||||
bin2str(self.t))
|
||||
|
||||
cdef unsigned int bitCount(unsigned long long int x):
|
||||
cdef unsigned int i=0
|
||||
|
Reference in New Issue
Block a user