I'm already aware of the following:
arrays
bitsets
hash maps and sets
regular maps and sets
iterators
lists
pairs
tuples
queues, deques, and priority queues
stacks
valarrays
vectors
Is there any other type of data structure available in the C++ library. What I'm specifically looking for is graphs, but I'd also like to know what else is there.
Also, I'd like to know if there are any external libraries I can link with my projects to implement a graph.
It's "the C++ standard library" or something to that effect, not "the STL". That term refers to an initial draft of some specific data structures and algorithms. Not all of them made it into the standard library, and the standard library also contains other stuff (for example, all the iostream classes).
That looks like a complete list to me (you appear to be talking specifically about C++0x, since you mention tuples and arrays). I don't know if I would even consider bitsets and iterators to be "data structures", but I guess that's a fair description.
There is definitely not a graph implementation. Unfortunately. :( You can get one from Boost, though.
The STL is divided into three parts:
Containers
Iterators
Algorithms
You have obviously found the containers part and you have probably used the iterators associated with the containers. But there is even more to the iterators than you have found.
The algorithms sections is linked to the containers via iterators. But also contains the parts handle functors and associated binders.
My favortie site for this is: http://www.sgi.com/tech/stl/table_of_contents.html
In addition to the standard libraries you should have a look at the boost libraries:
see also: Boost Library
Related
Is there any STL for segment tree?
In competitive programming it takes a lot of time to code for seg tree. I wonder if there is any STL for that so that lot of time could be saved.
I assume by "segment tree" you actually mean range tree, which is more commonly used in programming contests than the more specialized structure for storing a set of intervals.
There is no such container in the C++ standard library but if you are competing in ACM contests you can consider writing your own and simply copying it as needed. You can find my own implementation here (including lazy propagation) but if you search the web you can probably find a more generic version.
In applications where you need the sum instead of the minimum or maximum, you can use a binary indexed tree instead of a segment tree, which is faster, uses less memory, and is also easier to code (about a dozen lines or less).
There is no STL in C++ for segment tree. However, you can check out the Boost Library called Interval Container Library (ICL) which should satisfy your requirements.
I want to use vocabulary trees (which is not necessarily binary) in my program and I already have a general idea on how to create a tree class but I was wondering if there are any c++ libraries that are useful for that purpose. If not I would like to know about the methods I can use to manage my tree faster( add/remove/access nodes), like storing them in consecutive memory locations.
thank you
You can use The Boost Graph Library to model all kinds of trees.
Though std::map and std::set get mentioned in oleskii's link they are binary trees. Any n-ary tree can be rearranged to a binary tree, but that may not help you, since the re-organisation will take time. The boost graph libraries are more general purpose.
A quick google for n-ary trees C++" just turned up treetree
"Treetree is a header-only C++ library that implements a generic
tree-structured container class according to STL conventions"
If you want to make you current tree implementation faster, you should measure where it is currently slow.
Check simple things, e.g. make sure you pass by reference rather than by copy.
I know hash_set is non-standard and unordered_set is standard. However, I am wondering, performance wise, what is the difference between the two? Why do they exist separately?
The complexity requirements for the unordered_-containers set out by the C++ standard essentially don't leave much room for the implementation, which has to be some sort of hash table. The standard was written in full awareness that those data structures had already been deployed by most vendors as an extension.
Compiler vendors would typically call those containers "hash map" or "hash set", which is what you're probably referring to (there is no literal std::hash_set in the standard, but I think there's one in GCC in a separate namespace, and similarly for other compilers).
When the new standard was written, the authors wanted to avoid possible confusion with existing extension libraries, so they went for a name that reflects the typical C++ mindset: say what it is, not how it's implemented. The unordered containers are, well, unordered. That means you get less from them compared to the ordered containers, but this diminished utility affords you more efficient access.
Implementation-wise, hash_set, Boost-unordered, TR1-unordered and C++11-unordered will be very similar, if not identical.
Regarding the question "are they the same thing" from the subject line: based on my experience of upgrading code from __gnu_cxx::hash_set to std::unordered_set, they are almost, but not exactly, the same thing.
The difference that I ran into is that iterating through __gnu_cxx::hash_set returned the items in what appeared to be the original order of insertion, whereas std::unordered_set would not. So as the name implies, one cannot rely on an iterator to return the items in any particular order when iterating though the entire std::unordered_set.
Visual Studio 2010 for example has both hash_xxx and unordered_xxx, and if you look through the headers, atleast their implementation is the same for all of those (same base-/"policy"-classes).
For other compilers, I don't know, but due to how hash container usually have to be implemented, I guess there won't be many differences, if any at all.
They are pretty much the same things. The standard (C++0x) name is unordered_set. hash_set was an earlier name from boost and others.
We are porting out game from C++ to web; the game make extensive use of STL.
Can you provide short comparison chart (and if possible, a bit of code samples for basic operations like insertion/deletion/searching and (where applicable) equal_range/binary_search) for the classes what are equivalents to the following STL containers :
std::vector
std::set
std::map
std::list
stdext::hash_map
?
Thanks a lot for your time!
UPD:
wow, it seems we do not have everything we needhere :(
Can anyone point to some industry standard algorithms library for AS3 programs (like boost in C++)?
I can not believe people can write non-trivial software without balanced binary search trees (std::set std::map)!
The choices of data structures are significantly more limited in as3. You have:
Array or Vector.<*> which stores a list of values and can be added to after construction
Dictionary (hash_map) which stores key/value pairs
maps and sets aren't really supported as there's no way to override object equality. As for binary search, most search operations take a predicate function for you to override equality for that search.
Edit: As far as common algorithm and utility libraries, I'd take a look at as3commons
Maybe this library will fit your needs.
I'm developing a OpenGL based simulation in C++. I'm optmizing my code now and i see throughout the code the frequently use of std:list and std:vector. What is the more performatic: to continue using C++ stl data structs or a pointer based linked list? The main operation that involve std::list and std::vector is open a iterator and loop through all items in the data structs and apply some processing
How about stl containers of pointers?
It is highly unlikely that you will be able to develop better performing structures than the builtin. The only down part is the containers actually do contain copies of objects stored in them. If you're worried about this memory overhead (multiple structs hodling multiple copies of same objects, breaking consistency across the table) you should think about using stl structures of pointers to what you need.
Algorithmically speaking, the structure you need is implemented in the stl so you should use it. There is no need to reimplement the same structure.
Use C++ STL data structs, but use them efficiently. If you're using std::list and std::vector, look up such functions as find, for_each, accumulate, etc.
Here's some good reading:
http://www.cplusplus.com/reference/
Read the sections on algorithm, numeric, and functional. Also, I strongly recommend Scott Meyers' Effective STL.