I think it can be done in O(1) if concatenation >< allows concatenation xs >< reversed ys without penalty (some kind of hack is required in the structure of the fingers).
Looking at Data.Sequence , all operations have an inverse analogue (for example, takeWhileL ~ takeWhileR ) or take O(n) (or worse, for example zip take O(min(n1,n2)) , then seq1 n1<n2 , etc. .), except for the operation >< .
In any case, xs >< ys will take O(min(|xs|,|ys|)) as the worst case (two out of four possible cases). In practice, this is slightly better than O(n) (normalization to a unique direction and vice versa is required).
Then the question arises:
Can xs >< reversed ys be better than O(min(|xs|,|ys|)) ?
(ideally O(log(min(|xs|,|ys|))) )
Of course, if you do not use the >< operation, the reverse operation takes O(1) (for example, using a flag to check when using the left or right copy).
On the other hand, if the performance of concatenating inverse sequences is critical, there may be some other optimal structure, or you might consider using the @ d8d0d65b3f7cf42 strategy .
source share