this needs some optimize, the idea is to sorting an array of strings by divided them
to buckets ; each bucket has a label with alphabetical letter. e.g bucket #1 holds "a" strings.
Cheer$,
a.T.D
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
Have you considered what happens if there's an empty string or the first character of the string isn't 'a' to 'z'?
If there's 3 million strings that all happen to start with 'a', then how would those buckets help?
Have you considered using some form of binary tree?
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
If I were you I wouldn't use bucket sort. The best practice is to keep strings sorted, and use quick search to find where to insert a new string. Some time ago I had to wrote a session correlator, and I tested and benchmarked several sorting algorithms. Sessions where identified by session-id (a string), and I had to look up it very fast (there was about 1 million open session per sec), so it was quite a challange.
1. quick sort is slow in _most_ cases (it's only quick for a limited set of input)
2. bucket sort requires too much memory, and it's not so fast as I thought
3. no sorting algorithm can compete the "keep sorted and search on insert" way.
4. never ever use glib's bsearch, it's a buggy implementation
Thanx guys for your valuable replies, in fact am using this algorithm, because it is a distribution sort, so i can use multiprocessors for sorting.
@Brendan: you are completely right, in this case i should split up a very long series of string to sub-buckets !!!
@turdus: i can't keep string sorted, because i have to put some pre-knowable job for specific processor e.g buckets with even number are for core #2 ...
@berkus: I'm trying to mixup some theories with practice some times
Cheer$
a.T.d
Distance doesn't make you any smaller,
but it does make you part of a larger picture.