Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: "Clive D. W. Feather" <clive@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 16 Feb 2008 17:53:24 +0000
In article <GbGdnb81Zd2MlSvaRVnyjAA@xxxxxx>, Malcolm McLean
<regniztar@xxxxxxxxxxxxxx> writes
Of course after a swap I'd expect x to equal the former value of y and
y to equal x,
Agreed.
which is impossible to achieve if x and y share bytes.
Not quite.
Suppose we are swapping n bytes starting at x and y, where y = x + k and
k < n. Then swapping is possible if, and only if:
for all i in 0 <= i < n-2k:
x [i] = x [i + 2k]
The easiest way to see this is to draw two parallel rows of boxes,
labelled "before" and "after", and link the boxes that must be the same.
--
Clive D.W. Feather | Home: <clive@xxxxxxxxxx>
Tel: +44 20 8495 6138 (work) | Web: <http://www.davros.org>
Fax: +44 870 051 9937 | Work: <clive@xxxxxxxxx>
Please reply to the Reply-To address, which is: <clive@xxxxxxxxxx>
.
- References:
- Results of the memswap() smackdown from the thread "Sorting" assignment
- From: spinoza1111
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: spinoza1111
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: Mike
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: spinoza1111
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: Malcolm McLean
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: spinoza1111
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: Malcolm McLean
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: Randy Howard
- Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: Malcolm McLean
- Results of the memswap() smackdown from the thread "Sorting" assignment
- Prev by Date: Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- Next by Date: Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- Previous by thread: Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- Next by thread: Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- Index(es):
Relevant Pages
|
|