青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

stl-什么時(shí)候用那種container?

Overview of Container Abilities
  Vector Deque List Set Multiset Map Multimap
Typical internal data structure Dynamic array Array of arrays Doubly linked list Binary tree Binary tree Binary tree Binary tree
Elements Value Value Value Value Value Key/value pair Key/value pair
Duplicates allowed Yes Yes Yes No Yes Not for the key Yes
Random access available Yes Yes No No No With key No
Iterator category Random access Random access Bidirectional Bidirectional (element constant) Bidirectional (element constant) Bidirectional (key constant) Bidirectional (key constant)
Search/find elements Slow Slow Very slow Fast Fast Fast for key Fast for key
Inserting/removing of elements is fast At the end At the beginning and the end Anywhere
Inserting/removing invalidates iterators, references, pointers On reallocation Always Never Never Never Never Never
Frees memory for removed elements Never Sometimes Always Always Always Always Always
Allows memory reservation Yes No
Transaction safe (success or no effect) Push/pop at the end Push/pop at the beginning and the end All except sort() and assignments All except multiple-element insertions All except multiple-element insertions All except multiple-element insertions All except multiple-element insertions


As a supplement to the table, the following rules of thumb might help:

  • By default, you should use a vector. It has the simplest internal data structure and provides random access. Thus, data access is convenient and flexible, and data processing is often fast enough.

  • If you insert and/or remove elements often at the beginning and the end of a sequence, you should use a deque. You should also use a deque if it is important that the amount of internal memory used by the container shrinks when elements are removed. Also, because a vector usually uses one block of memory for its elements, a deque might be able to contain more elements because it uses several blocks.

  • If you insert, remove, and move elements often in the middle of a container, consider using a list. Lists provide special member functions to move elements from one container to another in constant time. Note, however, that because a list provides no random access, you might suffer significant performance penalties on access to elements inside the list if you only have the beginning of the list.

    Like all node-based containers, a list doesn't invalidate iterators that refer to elements, as long as those elements are part of the container. Vectors invalidate all of their iterators, pointers, and references whenever they exceed their capacity, and part of their iterators, pointers, and references on insertions and deletions. Deques invalidate iterators, pointers, and references when they change their size, respectively.

  • If you need a container that handles exceptions in a way that each operation either succeeds or has no effect, you should use either a list (without calling assignment operations and sort() and, if comparing the elements may throw, without calling merge (), remove(), remove_if(), and unique(); see page 172) or an associative container (without calling the multiple-element insert operations and, if copying/assigning the comparison criterion may throw, without calling swap()). See Section 5.11.2, for a general discussion of exception handling in the STL and Section 6.10.10, for a table of all container operations with special guarantees in face of exceptions.

  • If you often need to search for elements according to a certain criterion, use a set or a multiset that sorts elements according to this sorting criterion. Keep in mind that the logarithmic complexity involved in sorting 1,000 elements is in principle ten times better than that with linear complexity. In this case, the typical advantages of binary trees apply.

    A hash table commonly provides five to ten times faster lookup than a binary tree. So if a hash container is available, you might consider using it even though hash tables are not standardized. However, hash containers have no ordering, so if you need to rely on element order they're no good. Because they are not part of the C++ standard library, you should have the source code to stay portable.

  • To process key/value pairs, use a map or a multimap (or the hash version, if available).

  • If you need an associative array, use a map.

  • If you need a dictionary, use a multimap.

posted on 2005-12-14 09:02 夢在天涯 閱讀(1643) 評論(1)  編輯 收藏 引用 所屬分類: STL/Boost

評論

# re: stl-什么時(shí)候用那種container? 2005-12-14 11:34 力為

Effective STL Item One is also helpful.  回復(fù)  更多評論   

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1811750
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              亚洲精品自在在线观看| 欧美高清在线| 欧美激情免费观看| 国产精品美女久久福利网站| 欧美日韩在线播| 欧美亚一区二区| 国产伦精品一区二区三区在线观看| 国产精品视频网| 伊人久久噜噜噜躁狠狠躁| 亚洲第一搞黄网站| 日韩视频在线观看| 先锋亚洲精品| 免费欧美电影| 日韩亚洲欧美一区二区三区| 亚洲欧美清纯在线制服| 麻豆成人小视频| 国产精品v片在线观看不卡| 国产亚洲免费的视频看| 亚洲高清一区二区三区| 亚洲欧美日韩国产中文在线| 久久综合九九| 亚洲自拍偷拍麻豆| 欧美~级网站不卡| 国产精品网站一区| 亚洲激情一区二区三区| 欧美一级久久| 亚洲久久成人| 久久综合给合| 国产精品视频久久| 日韩亚洲精品在线| 久久精品久久综合| 一区二区国产精品| 免费成人av在线| 国产一区二区三区网站| 亚洲午夜一区二区三区| 亚洲第一中文字幕| 亚洲少妇中出一区| 欧美激情一区二区三区成人| 精品不卡在线| 久久国产加勒比精品无码| 一本一本a久久| 欧美精品免费播放| 亚洲黄色在线看| 久久综合色天天久久综合图片| 一区二区日韩伦理片| 欧美激情1区| 亚洲片在线资源| 欧美激情久久久久| 久久亚洲精品网站| 在线免费观看视频一区| 久久久亚洲欧洲日产国码αv| 亚洲视频免费观看| 欧美日韩综合久久| 亚洲一区二区三区精品在线观看| 欧美激情一区二区三区蜜桃视频 | 亚洲伦理网站| 欧美国产在线电影| 日韩视频一区二区三区| 亚洲电影免费观看高清| 欧美成人网在线| 欧美日韩高清不卡| 99精品欧美| 亚洲精品视频一区二区三区| 农村妇女精品| 亚洲人人精品| 亚洲精品乱码| 欧美日韩国产在线一区| 亚洲专区一区| 久久精品30| 91久久午夜| 一区二区三区国产盗摄| 国产精品久久久久久久电影| 欧美一区二区三区四区高清| 久久国产精品亚洲va麻豆| 影院欧美亚洲| 999亚洲国产精| 国产精品欧美一区喷水| 久久久久国产精品午夜一区| 久久久水蜜桃| 一本色道久久88综合日韩精品 | 久久中文字幕导航| 久久夜色精品国产欧美乱| 亚洲精品自在在线观看| 亚洲午夜免费视频| 黄色国产精品一区二区三区| 91久久国产综合久久蜜月精品| 欧美日韩在线免费观看| 久久精品一本| 欧美日韩国产综合视频在线观看| 欧美一区二区视频观看视频| 久久先锋影音| 午夜天堂精品久久久久| 美女精品自拍一二三四| 亚洲欧美日韩国产一区二区三区| 麻豆成人小视频| 久久成人在线| 欧美久久视频| 老牛影视一区二区三区| 欧美视频亚洲视频| 久久一区二区精品| 欧美日韩免费视频| 欧美成人免费大片| 国产精品日韩欧美大师| 欧美国产激情| 国产日韩精品久久| 99re6这里只有精品| 怡红院精品视频| 亚洲一区二区三区四区视频| 亚洲毛片网站| 久久亚洲私人国产精品va媚药 | 在线播放日韩欧美| 亚洲欧美日韩一区二区| 日韩一二在线观看| 久久只有精品| 久久久精品一区二区三区| 欧美日韩亚洲一区三区| 欧美国产日韩一区二区在线观看| 国产日韩欧美黄色| 宅男精品视频| 中日韩午夜理伦电影免费| 久热精品视频在线观看| 欧美成人激情视频免费观看| 99精品久久久| 夜夜嗨av一区二区三区网页| 亚洲第一中文字幕| 欧美在线首页| 久久激情视频| 国产欧美一区二区三区在线老狼| 日韩一级在线| av72成人在线| 欧美成人在线网站| 欧美激情精品久久久六区热门 | 久久久91精品国产一区二区三区| 欧美视频日韩| 一区二区高清| 亚洲欧美国产77777| 国产精品日韩在线观看| 亚洲一区二区四区| 欧美专区日韩视频| 国产一区二区成人久久免费影院| 久久精品99无色码中文字幕| 久久久久久尹人网香蕉| 激情综合五月天| 久久人人爽人人爽| 欧美黄污视频| 一本久久青青| 欧美午夜在线| 亚洲欧洲av一区二区| 久久人人97超碰精品888| 狠狠久久综合婷婷不卡| 美脚丝袜一区二区三区在线观看| 欧美高清视频在线播放| av成人老司机| 国产欧美精品一区二区色综合| 欧美一区=区| 欧美大片在线看| 亚洲一区二区动漫| 国产一区二区中文| 蜜臀va亚洲va欧美va天堂| 亚洲精品视频免费观看| 性欧美xxxx视频在线观看| 国内成人在线| 欧美区在线观看| 亚洲欧美国产高清va在线播| 老鸭窝91久久精品色噜噜导演| 日韩一区二区精品葵司在线| 国产精品国产自产拍高清av王其 | 久久久不卡网国产精品一区| 亚洲电影av| 欧美系列亚洲系列| 欧美在线网站| 一本久久知道综合久久| 久久人人看视频| 亚洲午夜伦理| 亚洲电影成人| 国产精品蜜臀在线观看| 久热精品视频| 香蕉成人伊视频在线观看| 亚洲国产精品黑人久久久| 亚洲综合999| 亚洲精品欧洲精品| 国产亚洲成av人片在线观看桃| 欧美国产日韩一区二区三区| 午夜欧美大片免费观看| 亚洲三级视频在线观看| 久久香蕉精品| 亚洲欧美一区二区三区久久| 国产精品成人观看视频免费 | 亚洲大片精品永久免费| 午夜精品视频在线观看一区二区| 尤物yw午夜国产精品视频| 国产精品美女一区二区| 欧美啪啪成人vr| 免费成人av在线| 久久精品日韩| 欧美一区二区女人| 亚洲一二三四久久| 亚洲免费成人| 亚洲精品国精品久久99热| 欧美国产日韩xxxxx|