Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: [OT] Swapping buffers in place.

by BrowserUk (Patriarch)
on Mar 01, 2015 at 06:42 UTC ( [id://1118232]=note: print w/replies, xml ) Need Help??


in reply to Re: [OT] Swapping buffers in place.
in thread [OT] Swapping buffers in place.

I can do it with just one temp and n+m+(m-n) swaps (on paper):

0 1 2 3 4 5 6 7 8 [a b c d e f 1 2 3] temp [d]>>>>>>>>>>>[d] temp = *(p1+p1len+1) // want t +o move [0]->[3] so put [3]->temp (1) [a]>>>[d] *(p1+p1len+1) = *(p1+0) // [0]->[ +3] (2) [e]<<<<<[e] *(p1+0) = *(p1+p1len+2) // want t +o move [1]->[4] so put [4]->[0] (3) [b]>>>[b] *(p1+p1len+2) = *(p1+1) // [1]->[ +4] (4) [f]<<<<<[f] *(p1+1) = *(p1+p1len+3) // want t +o move [2]->[5] so put [5]->[1] (5) [c]>>>[c] *(p1+p1len+3) = *(p1+2) // [2]->[ +5] leaving [2] free so (6) [3]<<<<<<<<<[3] *(p1+2) = *(p2+p2len-1) // [2]<-[ +8] leaving [8] free so (7) [f]>>>>>>>>>>>[f] *(p2+p2len-1) = *(p1+1) // [1]->[ +8] leaving [1] free so (8) [2]<<<<<<<<<[2] *(p1+1) = *(p2+p2len-2) // [1]<-[ +7] leaving [7] free so (9) [e]>>>>>>>>>>>[e] *(p2+p2len-2) = *(p1+0) // [0]->[ +7] leaving [0] free so (10) [1]<<<<<<<<<[1] *(p1+0) = *(p2+p2len-3) // [0]<-[ +6] which leaves [6] free (11) [d]<<<<<[d] *(p2+p2len-3) = temp; // for th +e value in temp (12) [1 2 3 a b c d e f] m=6, n= +3, moves= 6+3+(6-3) = 12

But I'm damned if I can see any pattern to the increments & decrements or steps; to capture that for a generic M+N?

the triple reverse (which really is only two passes through the whole thing).

That's really quite brilliant, I'd never have thought of that :), and it will certainly be what O shall fall back to if I can't get this working.

But as the left buffers are going to be 2GB or 4GB or 8GB or 16GB or 32GB (depending on physical memory in the machine)

and the right buffer could be anything from 16 bytes up to the (leftBufferSize)-16 (ie. whatever is left in the dataset modulus the leftBufferSize)

you can see why I'd rather avoid (M+N)*2 if I can get M+N+(M-N). (And also why a 3 buffer is impractical.)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
m=6, n=3, moves= 6+3+(6-3) = 12

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1118232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found