Re: Results of the memswap() smackdown from the thread "Sorting" assignment
- From: Randy Howard <randyhoward@xxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Feb 2008 21:26:46 GMT
On Tue, 12 Feb 2008 12:43:21 -0600, Ben Bacarisse wrote
(in article <87odamnhh2.fsf@xxxxxxxxx>):
spinoza1111 <spinoza1111@xxxxxxxxx> writes:
On Feb 12, 8:26Â pm, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:
spinoza1111 <spinoza1...@xxxxxxxxx> writes:
I've optimized my search for unmatched characters (by replacing looped
pointer calculations with separate pointers) as well as fixing the bug
you found, Ben,
Not your day. See below...
We all live in anticipation of that wonderful day arriving. :)
// ***** spinoza1111's code with memcspn *****
void spinoza1111_memswap(char *ptrToA,
char *ptrToB,
int intLength)
{
int intIndex1 = 0;
char chrExchange;
char *ptrToAwork = ptrToA;
char *ptrToBwork = ptrToB;
while (intIndex1 < intLength)
{
for (;
intIndex1++ < intLength
&&
*ptrToAwork++ == *ptrToBwork++;);
if (intIndex1 >= intLength) break;
You've put a new bug in. Plug this into my posted test code and
you'll see it fails all the small swap tests. Just follow though the
case of:
char *s = "AB";
spinoza1111_memswap(s, s+1, 1);
and you'll see it swaps nothing rather than producing "BA".
I should have tested it myself. I asked him if he had tested the
results and not just measured the performance, and he didn't answer,
which should have inspired me to to dig deeper.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw
.
- Follow-Ups:
- 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: Ben Bacarisse
- 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: Ben Bacarisse
- 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
|