fixes to thiersort_apply - not sure actually but promising
This commit is contained in:
parent
873c17f658
commit
5df76664bb
23
thiersort.h
23
thiersort.h
@ -426,23 +426,25 @@ static inline void thiersort_apply(
|
|||||||
/* Replace the whole chain starting at i (j for chain index) */
|
/* Replace the whole chain starting at i (j for chain index) */
|
||||||
/* This works because we can easily check what does'nt need moves anymore. */
|
/* This works because we can easily check what does'nt need moves anymore. */
|
||||||
TSU32 j = i;
|
TSU32 j = i;
|
||||||
TSU32 ni = sortres[j].i;
|
TSU32 ni = sortres[j].i; /* (*) */
|
||||||
|
|
||||||
/* Until would move to its own position, chain */
|
/* Until would move to its own position, chain */
|
||||||
/* This also solves "already at right place" originals. */
|
/* This also solves "already at right place" originals. */
|
||||||
while(ni != j) {
|
while(ni != j) {
|
||||||
/* xchg j and ni */
|
/* xchg j and ni - but only if not already swapped! See: (*) */
|
||||||
memcpy(tmp, &((TSU8*)arr)[(size_t)j * elemsize], elemsize);
|
if(sortres[ni].i != ni) {
|
||||||
memcpy(
|
memcpy(tmp, &((TSU8*)arr)[(size_t)j * elemsize], elemsize);
|
||||||
&((TSU8*)arr)[(size_t)j * elemsize],
|
memcpy(
|
||||||
&((TSU8*)arr)[(size_t)ni * elemsize],
|
&((TSU8*)arr)[(size_t)j * elemsize],
|
||||||
elemsize);
|
&((TSU8*)arr)[(size_t)ni * elemsize],
|
||||||
memcpy(&((TSU8*)arr)[(size_t)ni * elemsize], tmp, elemsize);
|
elemsize);
|
||||||
|
memcpy(&((TSU8*)arr)[(size_t)ni * elemsize], tmp, elemsize);
|
||||||
|
}
|
||||||
|
|
||||||
/* Mark j index as done in sortres for outer loop. */
|
/* Mark j index as done in sortres for outer loop. */
|
||||||
/* This is necessary for inner loop stopping early */
|
/* This is necessary for inner loop stopping early */
|
||||||
/* and outer catch up on already processed location. */
|
/* and outer catch up on already processed location. */
|
||||||
sortres[j].i = j;
|
sortres[j].i = j; /* (*) */
|
||||||
|
|
||||||
/* Update j and ni */
|
/* Update j and ni */
|
||||||
/* Now we must find what should be at new location j */
|
/* Now we must find what should be at new location j */
|
||||||
@ -451,6 +453,9 @@ static inline void thiersort_apply(
|
|||||||
ni = sortres[j].i;
|
ni = sortres[j].i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Release mem - better we do because we changed it behind the scenes! */
|
||||||
|
free(sortres);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user