Message61112
something to make it a little more efficient to
build stuff on long integers; some simple things which
are much faster to do in C than in python:
e.g.
n.bitwid() 1+ floor(log2(abs(n)) - # of useful bits
n.bit(x) (n>>x)&1
n.bit(hi,lo) (n>>lo) & ( (1<<(hi-lo))-1)
n.bitrev(m) - reverse the lower m bits of n,
return that
n.findup( val=1, startbit=0)
"search leftwards for a bit matching 'val',
starting at
bit 'startbit'; -1 if none"
n.finddown(val=1, startbit=n.bitwid())
" search rightwards"
And some which would depend on the underlying
implementation (which appears to be pretty much
cast in cement, if not actual stone) :
n.bitarray() returns array.array('H') containing
raw bits
long_fromarray(seq, neg=0) - reverse of n.bitarray
If there's any interest in this, and no reason to shoot it
down right away, I cld write a PEP on it.
It would also be nice to have field-insertion operators,
that raises the question of wether these should return
a new long, or wether they should be built on a
mutable 'bit-sequence' type which can act like a long.
Maybe this should be an 'array-of-bit' suggestion....
|
|
Date |
User |
Action |
Args |
2008-01-20 09:59:25 | admin | link | issue722647 messages |
2008-01-20 09:59:25 | admin | create | |
|