Improve the performance of radixsort() when

sorting strings with common prefixes by noting
when all the strings land in just one bin.

Testing shows significant speedups (on the order of
30%) on strings with common prefixes and no slowdowns on any
of my test cases.

Submitted by: Markus Bjartveit Kruger <markusk@pvv.ntnu.no>
PR: 58860
Approved by: gordon (mentor)
This commit is contained in:
Tim Kientzle 2003-11-11 04:59:23 +00:00
parent b10221ffd9
commit 669073a7e6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=122458

View file

@ -176,6 +176,17 @@ r_sort_a(a, n, i, tr, endch)
}
}
/*
* Special case: if all strings have the same
* character at position i, move on to the next
* character.
*/
if (nc == 1 && count[bmin] == n) {
push(a, n, i+1);
nc = count[bmin] = 0;
continue;
}
/*
* Set top[]; push incompletely sorted bins onto stack.
* top[] = pointers to last out-of-place element in bins.