Re: [PATCH 1/8] lib/sort: Heapsort implementation of sort()
From: Paulo Marques (pmarques_at_grupopie.com)
Date: 01/31/05
- Previous message: Nix: "Re: 2.6.10: SPARC64 mapped figure goes unsignedly negative..."
- In reply to: Andreas Gruenbacher: "Re: [PATCH 1/8] lib/sort: Heapsort implementation of sort()"
- Next in thread: Matt Mackall: "Re: [PATCH 1/8] lib/sort: Heapsort implementation of sort()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 Jan 2005 17:30:42 +0000 To: Andreas Gruenbacher <agruen@suse.de>
Andreas Gruenbacher wrote:
> [...]
>
> static inline void swap(void *a, void *b, int size)
> {
> if (size % sizeof(long)) {
> char t;
> do {
> t = *(char *)a;
> *(char *)a++ = *(char *)b;
> *(char *)b++ = t;
> } while (--size > 0);
> } else {
> long t;
> do {
> t = *(long *)a;
> *(long *)a = *(long *)b;
> *(long *)b = t;
> size -= sizeof(long);
> } while (size > sizeof(long));
You forgot to increment a and b, and this should be "while (size);", no?
> }
> }
Or better yet,
static inline void swap(void *a, void *b, int size)
{
long tl;
char t;
while (size >= sizeof(long)) {
tl = *(long *)a;
*(long *)a = *(long *)b;
*(long *)b = tl;
a += sizeof(long);
b += sizeof(long);
size -= sizeof(long);
}
while (size) {
t = *(char *)a;
*(char *)a++ = *(char *)b;
*(char *)b++ = t;
size--;
}
}
This works better if the size is not a multiple of sizeof(long), but is
bigger than a long.
However it seems that this should be put in a generic library function...
-- Paulo Marques - www.grupopie.com All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke (1729 - 1797) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Previous message: Nix: "Re: 2.6.10: SPARC64 mapped figure goes unsignedly negative..."
- In reply to: Andreas Gruenbacher: "Re: [PATCH 1/8] lib/sort: Heapsort implementation of sort()"
- Next in thread: Matt Mackall: "Re: [PATCH 1/8] lib/sort: Heapsort implementation of sort()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|