in reply to Re: [OT] Swapping buffers in place. (partial solution:needs more help!)
in thread [OT] Swapping buffers in place.
I've copied what you did and added the iterator and reexpressed the righthand sides in terms of the lengths (the lefts are just the rights from the previous line) and the pattern starts to show up (at least if you click on "download" to view it spread out).
p2+p2len -3-2-1 p2 +0+1+2 p1+p1len-6-5-4-3-2-1 p1 +0+1+2+3+4+5 0 1 2 3 4 5 6 7 8 [a b c d e f 1 2 3] temp I RHS [1]>>>>>>[1] temp = *(p2+0) 0 *(p2 ++0) [d]>>>[d] *(p2+0) = *(p1+3) 0 *(p1 ++(p1len-p2len)) [a]>>>[a] *(p1+3) = *(p1+0) 0 *(p1 ++I) [1]<<<<<<<<<<<<<<<<<<[1] *(p1+0) = temp [2]>>>>[2] temp = *(p2+1) 1 *(p2 ++I) [e]>>>[e] *(p2+1) = *(p1+4) 1 *(p1 ++(p1len-p2len)+I) [b]>>>[b] *(p1+4) = *(p1+1) 1 *(p1 ++I) [2]<<<<<<<<<<<<<<<<[2] *(p1+1) = temp [3]>>[3] temp = *(p2+2) 2 *(p2 ++I) [f]>>>[f] *(p2+2) = *(p1+5) 2 *(p1 ++(p1len-p2len)+I) [c]>>>[c] *(p1+5) = *(p1+2) 2 *(p1 ++I) [3]<<<<<<<<<<<<<<[3] *(p1+2) = temp [1 2 3 a b c d e f]
The pattern doesn't jump out as easily from your second example.
EDIT: I think I got the second one, too. There was a typo that messed me up for a bit, and you solved this one "backwards" so it's easier to reference from the ends of the buffers than the starts, but again there's a pattern:
where the addition has to wrap around as graff describesp2+p2len -4-3-2-1 p2 +0+1+2+3 p1+p1len-9-8-7-6-5-4-3-2-1 L1=la +st element of buffer 1 p1 +0+1+2+3+4+5+6+7+8 L2=la +st element of buffer 2 0 1 2 3 4 5 6 7 8 diff= +p1len-p2len=5 [a b c d e f g h i 1 2 3 4] temp I [4]>>[4] temp = *(p2+3) 0 + *(L2+I) [i]>>>>>[i] *(p2+3) = *(p1+8) 0 + *(L1+I) [e]>>>>>[e] *(p1+8) = *(p1+4) 0 + *(L1-diff+1+I) [a]>>>>>[a] *(p1+4) = *(p1+0) 1 + *(L2+I) [1]<<<<<<<<<<<<<<<[1] *(p1+0) = *(p2+0) 1 + *(L1+I) [f]>>>>>[f] *(p2+0) = *(p1+5) 1 + *(L1-diff+1+I) [b]>>>>>[b] *(p1+5) = *(p1+1) 2 + *(L2+I) [2]<<<<<<<<<<<<<<<[2] *(p1+1) = *(p2+1) 2 + *(L1+I) # I think you had a typo here [g]>>>>>[g] *(p2+2) = *(p1+6) 2 + *(L1-diff+1+I) [c]>>>>>[c] *(p1+6) = *(p1+2) 3 + *(L2+I) [3]<<<<<<<<<<<<<<<[3] *(p1+2) = *(p2+2) 3 + *(L1+I) [h]>>>>>[h] *(p2+2) = *(p1+7) 3 + *(L1-diff+1+I) [d]>>>>>[d] *(p1+7) = *(p1+3) 4 + *(L2+I) [4]<<<<<<<<<<<<<<<<<<<<[4] *(p1+3) = temp [1 2 3 4 a b c d e f g h i]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: [OT] Swapping buffers in place. (partial solution:needs more help!)
by BrowserUk (Patriarch) on Mar 01, 2015 at 10:35 UTC |