I am looking for a "List" with input / removal log (N) in index i. I put the word "List" in quotation marks because I do not mean that this is the actual Haskell list, but only any ordered container with a bunch of objects (in fact, it probably needs some kind of tree inside). I am surprised that I have not yet found a great solution ....
This is the best solution I have so far. Use Data.Sequence with these two functions.
doInsert position value seq = before >< ( value <| after) where (before, after) = splitAt position seq doDelete position seq = before >< (drop 1 after) where (before, after) = splitAt position seq
Although this is technically all the functions of the log (N), it seems to me that I am doing a bunch of additional materials for each insert / delete ... In other words, it scales like K * log (N) for K, which is more than it should be. Plus, since I have to define this material myself, I feel like I'm using Sequence for something that it's not intended for.
Is there a better way?
This is a related question (although it only applies to sequences, I would love to use something else): Why Data.Sequence does not have “insert” or “insertBy”, and how can I effectively implement them?
And yes, this question is related to this other that I posted a few days ago: Massive amount of XML changes
haskell
jamshidh
source share