Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does any std::set implementation not use a red-black tree?

Has anyone seen an implementation of the STL where stl::set is not implemented as a red-black tree?

The reason I ask is that, in my experiments, B-trees outperform std::set (and other red-black tree implementations) by a factor of 2 to 4 depending on the value of B. I'm curious if there is a compelling reason to use red-black trees when there appear to be faster data structures available.

like image 392
Pat Morin Avatar asked Oct 24 '14 14:10

Pat Morin


1 Answers

Some folks over at Google actually built a B-tree based implementation of the C++ standard library containers. They seem to have much better performance than standard binary tree implementations.

There is a catch, though. The C++ standard guarantees that deleting an element from a map or set only invalidates other iterators pointing to the same element in the map or set. With the B-tree based implementation, due to node splits and consolidations, the erase member functions on these new structures may invalidate iterators to other elements in the tree. As a result, these implementations aren't perfect replacements for the standard implementations and couldn't be used in a conformant implementation.

Hope this helps!

like image 161
templatetypedef Avatar answered Oct 25 '22 00:10

templatetypedef