Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using STL's Internal Implementation of Red-Black Tree

I understand that my STL (that comes with g++ 4.x.x) uses red-black trees to implement containers such as the map. Is it possible to use the STL's internal red-black tree directly. If so, how? If not, why not - why does STL not expose the red-black tree?

Surprisingly, I cannot find an answer using google.

Edit: I'm investigating using the red-black tree as a solution to the extra allocator constructor call on insertion. See this question. My STL uses red-black trees for map implementation.

like image 536
Prasoon Tiwari Avatar asked Jul 08 '12 06:07

Prasoon Tiwari


1 Answers

Actually - the answer is very simple, and independent of your version of gcc. You can download the stl source code from sgi's website, and see the implementation and use for yourself.

For example, in version 3.2, you can see the red-black tree implementation in the stl_tree.h file, and an example of its use in stl_set.h.

Note that since the stl classes are template classes, the implementations are actually inside the header files.

like image 136
Guy Adini Avatar answered Sep 21 '22 01:09

Guy Adini