I have written an algorithm, which can order and sort large numbers of items.
It creates a pyramidal directory, moving entries and groups accordingly.
Items can be added, removed and looked-up in constant low time.
This is the standard-implementation, there are two more implementations in C and C#.
You can find detailed information in the Wiki.