bitstring icon indicating copy to clipboard operation
bitstring copied to clipboard

Accept xrange-like parameters as well as iterables.

Open GoogleCodeExporter opened this issue 10 years ago • 2 comments

Some methods that accept iterables end up spending a lot of time
range-checking elements. This isn't really needed, as often the iterable is
an xrange or range object, and the whole range checking could be done once.

Suggest that range-like parameters be accepted so that quicker checks could
be performed.

For example:

s.allset(xrange(s.len)) -> s.allset(0, s.len)

s.set(xrange(100, 0, -5)) -> s.set(100, 0, -5)

Points to note:

1) Can't replace xrange(n) with just 'n'. Would need to say (0, n).
2) Could be confusion between ([a, b, c]) and (a, b, c).

Original issue reported on code.google.com by [email protected] on 31 May 2010 at 8:46

GoogleCodeExporter avatar Apr 11 '15 20:04 GoogleCodeExporter

Perhaps a better alternative would be:

s.set(slice(a, b, c))

This avoids the nasty variable number of arguments, and the confusion with 
s.set((a,
b, c)).

Original comment by [email protected] on 1 Jun 2010 at 4:13

GoogleCodeExporter avatar Apr 11 '15 20:04 GoogleCodeExporter

I'm not sure what is meant here, but I think this covered by the indexing syntax:

>>> data = BitArray('0b1111')
>>> data[0:3] = 0b000
>>> data[0:2] = 0b11
0b1101

florisla avatar Jul 27 '18 15:07 florisla

There is now an optimisation for using a range object when calling set. I think I can close this one!

scott-griffiths avatar May 27 '23 20:05 scott-griffiths