How are sets generally implemented in STL. I have read they are
implemented as BST, are they some kind of balanced BST like Red Black
trees?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
manan.chopra (6)
|
8/7/2010 8:05:07 PM |
|
On 2010-08-08, MC <manan.chopra@gmail.com> wrote:
>
> How are sets generally implemented in STL. I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
>
The standard specifies only complexity requirements: insertion and
search must
be O(log n) (in the number of elements already in the tree) worst-case.
Thus,
e.g., both red-black trees and AVL trees qualify.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Zeljko
|
8/9/2010 8:30:32 AM
|
|
On Aug 8, 4:05 am, MC <manan.cho...@gmail.com> wrote:
> How are sets generally implemented in STL. I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
It's necessarily some kind of self-balancing binary tree since that's
the only way to provide the complexity guarantees that are required.
Implementations typically use a red-black tree or an AVL tree.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Mathias
|
8/9/2010 8:53:36 AM
|
|
On 08/08/10 05:05, MC wrote:
> How are sets generally implemented in STL. I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
>
AFAIK, yes, Red Black Trees are one of the most common implementations
for sets, maps and alikes. There are also AVL implementations out there,
that you can google for.
JP
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Juan
|
8/9/2010 8:55:01 AM
|
|
MC <manan.chopra@gmail.com> wrote:
> How are sets generally implemented in STL. I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
Yes.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Daniel
|
8/9/2010 8:28:36 PM
|
|
MC wrote, On 8.8.2010 5:05:
> How are sets generally implemented in STL. I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
The C++ ISO standard does not specify such implementation details, only run
time complexitis. For std::set<>, they pretty much imply some kind of search
tree. The standard library shipped with GCC uses Red-Black Tree and os does
the one shipped with VS.NET 2005.
--
VH
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Vaclav
|
8/9/2010 8:59:27 PM
|
|
On 8 ao�t, 05:05, MC <manan.cho...@gmail.com> wrote:
> How are sets generally implemented in STL.
Well, it depends on ... the implementation :)
> I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
IMO that's the obvious (I dare say intended) implementation. But
nothing prevents the implementer from providing more efficient
structures for specific specialization.
--
Michael
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Michael
|
8/9/2010 10:20:58 PM
|
|
On 8/7/2010 11:05 PM, MC wrote:
> How are sets generally implemented in STL. I have read they are
> implemented as BST, are they some kind of balanced BST like Red Black
> trees?
>
>
Every implementation I know of uses a red-black tree, although the
standard says nothing about which underlying data type to use.
Joe Gottman
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Joe
|
8/9/2010 10:29:33 PM
|
|
|
7 Replies
490 Views
(page loaded in 0.087 seconds)
Similiar Articles: STL allocators, global new/delete using the heap and shared memory ...Set implementation in STL - comp.lang.c++.moderated Using thread-specific data in shared libraries - comp ... of pthread_key_delete, proper implementation ... Thread safe hash_map in stl port linux - comp.lang.c++.moderated ...Set implementation in STL - comp.lang.c++.moderated Thread safe hash_map in stl port linux - comp.lang.c++.moderated ... Set implementation in STL - comp.lang.c++ ... associative ,set associative and direct mapping - comp.arch ...Set implementation in STL - comp.lang.c++.moderated This was definitely the case with the old SGI implementation. ... tr1::unordered_map - comp.lang ... associative ,set ... Overloading operators new and delete - comp.lang.c++.moderated ...Set implementation in STL - comp.lang.c++.moderated Overloading operators new and delete - comp.lang.c++.moderated ..... even though I'm not freeing it in the operator's ... Observable collections (set, list, map) - comp.lang.java ...Set implementation in STL - comp.lang.c++.moderated For std::set<>, they pretty much imply some kind of search tree. The standard ... STLport is based on the SGI ... A container library for C - comp.compilers.lccSet implementation in STL - comp.lang.c++.moderated A container library for C - comp.compilers.lcc (2) The source code of the sample implementation ... Binary Tree Interface - comp.lang.java.guiSet implementation in STL - comp.lang.c++.moderated It's necessarily some kind of self-balancing binary tree since that's the only way to ... Why set the event every time ... Thread-safe Queue on Win32 - comp.programming.threadsIs this implementation of thread-safe queue correct? ... > 2) Why set the event every time even if it was ... Thread safe hash_map in stl port linux - comp.lang ... Linking consistency check - comp.lang.c++.moderatedSet implementation in STL - comp.lang.c++.moderated Linking consistency check - comp.lang.c++.moderated The next issue is to ensure that the implementation file ... like ... std::stringstream and string to unsigned long conversion - comp ...The MSVC7 implementation does not check for these overflow ... it works as you describe, because it should not set ... or an equivalent class depending on the available STL ... Set implementation in STL C++/VB - C++/VB Discussion List Tuesday ...MC wrote, On 8.8.2010 5:05: The C++ ISO standard does not specify such implementation details, only run time complexitis. For std::set<>, they pretty much imply some ... Standard Template Library - Wikipedia, the free encyclopediaThe Standard Template Library (STL) is a C++ software library which ... The STL provides a ready-made set of common ... countered with special techniques within STL implementation ... 7/23/2012 4:55:49 PM
|