scott-griffiths / bitstring

A Python module to help you manage your bits
https://bitstring.readthedocs.io/en/stable/index.html
MIT License
401 stars 67 forks source link

Allow operations between Arrays #284

Closed scott-griffiths closed 11 months ago

scott-griffiths commented 11 months ago

For example with two arrays of the same length we could allow:

a = Array('int6', [1, 2, 3])
b = Array('int6', [5, 5, 5])
c = a + b  # Array('int6', [6, 7, 8])

which would make a new Array with elements that are sum of the other Array elements. Nothing too radical there, but it does mean that we can't use + to concatenate Arrays like we are currently. I don't really like how + has two meanings whereas -, * etc only have one, so I'm tempted to remove the + = concatenate meaning right now. You can still always extend after all.

So basically whenever we have op(array1, array2) we would try to apply that op on the elements of each array, if that makes sense.

Interesting questions arise if the formats of the two arrays are not the same - how do we determine the resultant format for operations that aren't in-place?