I got a list of objects which look like strings, but are not real strings (think about mmap'ed files). Like this:
x = [ "abc", "defgh", "ij" ]
What i want is x to be directly indexable like it was a big string, i.e.:
(x[4] == "e") is True
(Of course I don't want to do "".join(x) which would merge all strings, because reading a string is too expensive in my case. Remember it's mmap'ed files.).
This is easy if you iterate over the entire list, but it seems to be O(n). So I've implemented __getitem__ more efficiently by creating such a list:
x = [ (0, "abc"), (3, "defgh"), (8, "ij") ]
Therefore I can do a binary search in __getitem__ to quickly find the tuple with the right data and then indexing its string. This works quite well.
I see how to implement __setitem__, but it seems so boring, I'm wondering if there's not something that already does that.
To be more precise, this is how the data structure should honor __setitem__:
>>> x = [ "abc", "defgh", "ij" ]
>>> x[2:10] = "12345678"
>>> x
[ "ab", "12345678", "j" ]
I'd take any idea about such a data structure implementation, name or any hint.
__getitem__).__getitem__is overloaded inxclass (a subclass of list).