@@ -48,7 +48,7 @@ def _check_slice(len, i, j):
4848
4949class BitVec :
5050
51- def init (self , * params ):
51+ def __init__ (self , * params ):
5252 self ._data = 0L
5353 self ._len = 0
5454 if not len (params ):
@@ -93,20 +93,12 @@ def init(self, *params):
9393 else :
9494 raise error , 'bitvec() requires 0 -- 2 parameter(s)'
9595
96- return self
97-
98-
99- def _init (self , data , len ):
100- self ._data = data
101- self ._len = len
102- return self
103-
10496
10597 def append (self , item ):
10698 #_check_value(item)
10799 #self[self._len:self._len] = [item]
108100 self [self ._len :self ._len ] = \
109- BitVec (). _init ( long (not not item ), 1 )
101+ BitVec (long (not not item ), 1 )
110102
111103
112104 def count (self , value ):
@@ -138,7 +130,7 @@ def index(self, value):
138130 def insert (self , index , item ):
139131 #_check_value(item)
140132 #self[index:index] = [item]
141- self [index :index ] = BitVec (). _init ( long (not not item ), 1 )
133+ self [index :index ] = BitVec (long (not not item ), 1 )
142134
143135
144136 def remove (self , value ):
@@ -163,7 +155,7 @@ def sort(self):
163155
164156
165157 def copy (self ):
166- return BitVec (). _init ( self ._data , self ._len )
158+ return BitVec (self ._data , self ._len )
167159
168160
169161 def seq (self ):
@@ -229,7 +221,7 @@ def __getslice__(self, i, j):
229221 #rprt(`self`+'.__getslice__'+`i, j`+'\n')
230222 i , j = _check_slice (self ._len , i , j )
231223 if i >= j :
232- return BitVec (). _init ( 0L , 0 )
224+ return BitVec (0L , 0 )
233225 if i :
234226 ndata = self ._data >> i
235227 else :
@@ -239,7 +231,7 @@ def __getslice__(self, i, j):
239231 #we'll have to invent faster variants here
240232 #e.g. mod_2exp
241233 ndata = ndata & ((1L << nlength ) - 1 )
242- return BitVec (). _init ( ndata , nlength )
234+ return BitVec (ndata , nlength )
243235
244236 def __setslice__ (self , i , j , sequence , * rest ):
245237 #rprt(`self`+'.__setslice__'+`(i, j, sequence) + rest`+'\n')
@@ -274,16 +266,16 @@ def __mul__(self, multiplier):
274266 if type (multiplier ) != type (0 ):
275267 raise TypeError , 'sequence subscript not int'
276268 if multiplier <= 0 :
277- return BitVec (). _init ( 0L , 0 )
269+ return BitVec (0L , 0 )
278270 elif multiplier == 1 :
279271 return self .copy ()
280272 #handle special cases all 0 or all 1...
281273 if self ._data == 0L :
282- return BitVec (). _init ( 0L , self ._len * multiplier )
274+ return BitVec (0L , self ._len * multiplier )
283275 elif (~ self )._data == 0L :
284- return ~ BitVec (). _init ( 0L , self ._len * multiplier )
276+ return ~ BitVec (0L , self ._len * multiplier )
285277 #otherwise el cheapo again...
286- retval = BitVec (). _init ( 0L , 0 )
278+ retval = BitVec (0L , 0 )
287279 while multiplier :
288280 retval , multiplier = retval + self , multiplier - 1
289281 return retval
@@ -293,7 +285,7 @@ def __and__(self, otherseq, *rest):
293285 if type (otherseq ) != type (self ):
294286 otherseq = apply (bitvec , (otherseq , ) + rest )
295287 #sequence is now of our own type
296- return BitVec (). _init ( self ._data & otherseq ._data , \
288+ return BitVec (self ._data & otherseq ._data , \
297289 min (self ._len , otherseq ._len ))
298290
299291
@@ -302,7 +294,7 @@ def __xor__(self, otherseq, *rest):
302294 if type (otherseq ) != type (self ):
303295 otherseq = apply (bitvec , (otherseq , ) + rest )
304296 #sequence is now of our own type
305- return BitVec (). _init ( self ._data ^ otherseq ._data , \
297+ return BitVec (self ._data ^ otherseq ._data , \
306298 max (self ._len , otherseq ._len ))
307299
308300
@@ -311,13 +303,13 @@ def __or__(self, otherseq, *rest):
311303 if type (otherseq ) != type (self ):
312304 otherseq = apply (bitvec , (otherseq , ) + rest )
313305 #sequence is now of our own type
314- return BitVec (). _init ( self ._data | otherseq ._data , \
306+ return BitVec (self ._data | otherseq ._data , \
315307 max (self ._len , otherseq ._len ))
316308
317309
318310 def __invert__ (self ):
319311 #rprt(`self`+'.__invert__()\n')
320- return BitVec (). _init ( ~ self ._data & ((1L << self ._len ) - 1 ), \
312+ return BitVec (~ self ._data & ((1L << self ._len ) - 1 ), \
321313 self ._len )
322314
323315 def __coerce__ (self , otherseq , * rest ):
@@ -337,5 +329,4 @@ def __float__(self):
337329 return float (self ._data )
338330
339331
340- def bitvec (params ):
341- return apply (BitVec ().init , params )
332+ bitvec = BitVec
0 commit comments