Would I be better off using memoryview
, itertools.islice
or something else (e.g. var = (start, stop)
) as a pointer in Python to a substring of a very large string?
Context: I have some very long strings that I need to manipulate (cut and paste substrings, etc.) without creating a new string each time.
I accomplish that by making a binary search tree in which each node represents a substring and then using split/merge operations (a Rope data structure).
Each node needs a reference attached to it to the substring of the original very large string that the node represents. (That's necessary so that, when I walk the tree in-order to produce the final edited string, I get back the parts of the original string in the amended sequence.)
I could attach a tuple representing start/stop values to each node and then use slicing string[start:stop]
, but in C you would use a pointer and a character count.
Would it be better to do something similar in Python, either with memoryview
or with islice
or with something else?