[Python-bugs-list] [ python-Feature Requests-722647 ] lower-level API for longs

SourceForge.net noreply@sourceforge.net
Wed, 16 Apr 2003 11:07:16 -0700


Feature Requests item #722647, was opened at 2003-04-16 14:07
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=722647&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregory Smith (gregsmith)
Assigned to: Nobody/Anonymous (nobody)
Summary: lower-level API for longs

Initial Comment:
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....


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=722647&group_id=5470