If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Darn, I came in here hoping that you were posting your implementation, which I would then swipe with an audible "yoink".

If you have Cormen et al I would just translate their pseudocode and run with it, I have never had a problem arise with code copied from them. (Actually, I would first ask myself if a heap would suffice instead of r/b tree, but if you know enough to ask this question to begin with, you've probably already thought that part through).

I find that in most cases its incredibly hard to beat flashes built in data structures because they are implemented natively. Your best bet is changing the way you access them, such as binary trees built on top of an array.

The greatest pleasure in life is doing what people say you cannot do. - Walter BagehotThe height of cleverness is to be able to conceal it. - Francois de La Rochefoucauld

Performance very much depends on the usage. In my benchmarks I found that for storing strings, an object is very good up until 30,000 entries and then it becomes the same speed as using an RBTreeString. Perhaps it was using a hash table until it reached 2^15 entries?

Inserted strings ""+i for i=0..N, then queried for same strings in same order:

I run runTree3() once, then runTree4() twenty times and record the minimum. That's probably the most important thing in benchmarking: run multiple times and report the minimum, not the average. This is the best way to prune out the overhead in a shared-time operating system. The more runs the better, but twenty is pushing the 15s executing limit. Then I execute the whole program a few times and record that minimum. Chasing the minimum has busted some myths I've seen regarding the speed of "x++" vs "x = x + 1" for example (there is no speed difference between those two by the way).