|
Informal Poll : Favorite STL container |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Here's something I was wondering. Which data structure is your favorite and why? Personally I like std::map (Red Black tree) and std::deque (Double ended queue) the most, but map is my all time favorite. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
torhu
Member #2,727
September 2002
|
std::vector |
jmasterx
Member #11,410
October 2009
|
Nobody has said why I will also say vector. Agui GUI API -> https://github.com/jmasterx/Agui |
Edgar Reynaldo
Major Reynaldo
May 2007
|
@jmasterx Because I'm a sucker for non linear searches. Although for that reason I would prefer a hash map. But regular map is sorted, which is nice. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Eric Johnson
Member #14,841
January 2013
|
I'll also go with vector. It's just so convenient.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
If you like copying data and linear search, sure. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
torhu
Member #2,727
September 2002
|
Some useful ones added in C++11: std::unordered_map, std::unordered_set, and std::array. |
Chris Katko
Member #1,881
January 2002
|
This is like asking whether you prefer a philips or blade screwdriver. You use the right one for the job. {"name":"617lkr02DDL._SL1500_.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/4\/449c9949305b067d4f0bafb8ccd6dfd4.jpg","w":1500,"h":923,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/4\/449c9949305b067d4f0bafb8ccd6dfd4"} And if in doubt, shove it in the socket and turn: {"name":"15789.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3e8cd8a398f348c00e05eac31c1c0b23.jpg","w":1278,"h":849,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3e8cd8a398f348c00e05eac31c1c0b23"} I will admit that I almost never use trees because my work has never needed them. Most business (and 2-d game stuff) ends up being either vectors or associated maps. So I have no deep experience with them as I rarely need to solve a "tree" problem. I do LOVE quadtrees though. Spatial data structures make so much more intuitive sense for me. And BSP's are neat although, IIRC, you can't modify them easily so it goes tits-up if you want to say, have, a dynamic world represented in a BSP tree. Then again, Quake couldn't do it because of BSP's... but... Unreal Tournament could and they used BSPs... I wonder what they did to improve it? Then again, it still wasn't "that" dynamic. Moving platforms, rotating is different than say, Duke Nukem 3D with entire buildings collapsing while you play. -----sig: |
Peter Hull
Member #1,136
March 2001
|
I found the answer using Science: $ find . -name "*.cc" -exec grep "vector" '{}' + |wc 163 620 10133 $ find . -name "*.cc" -exec grep "list" '{}' + |wc 130 820 9985 $ find . -name "*.cc" -exec grep "map" '{}' + |wc 699 3389 43498 $ find . -name "*.cc" -exec grep "deque" '{}' + |wc 0 0 0 $ find . -name "*.cc" -exec grep "set" '{}' + |wc 965 6089 63995
|
MiquelFire
Member #3,110
January 2003
|
I took a flowchart someone posted here once and made a JS thing to allow me to pick the right one. --- |
SiegeLord
Member #7,827
October 2006
|
std::vector. Contiguous memory, cache friendly, nice API, faster than all other containers for small lengths (and not so small in case of the worst container, std::list). It's the perfect container. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Peter Hull said: I found the answer using Science: $ find . -name "*.cc" -exec grep "vector" '{}' + |wc 163 620 10133 $ find . -name "*.cc" -exec grep "list" '{}' + |wc 130 820 9985 $ find . -name "*.cc" -exec grep "map" '{}' + |wc 699 3389 43498 $ find . -name "*.cc" -exec grep "deque" '{}' + |wc 0 0 0 $ find . -name "*.cc" -exec grep "set" '{}' + |wc 965 6089 63995
Oh Peter, you really should give deque a try. Trust me, find a reason to use it and you'll love it. Surprisingly here, no one has mentioned a heap. :O My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
bamccaig
Member #7,536
July 2006
|
Link in my signature to the flowchart (not my creation). I have no favorite container. Also, I haven't been programming C++ much lately. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
relpatseht
Member #5,034
September 2004
|
Vectors and deques, but I rarely use the STL. Spatial trees are essential for games. Steer clear of BSP trees. They haven't been relevant in decades. Quadtrees make sense, but you're better off generalizing to an r-tree. You'll probably get the best perf via an 8 wide OBB tree, traversed/queried via AVX. I find k-means to be a great bulk loading strategy.
|
|