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

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>
              亚洲欧美激情视频| 亚洲天堂男人| 久久久青草青青国产亚洲免观| 一本久久精品一区二区| 欧美久色视频| 亚洲欧美激情视频| 亚洲欧美日韩综合一区| 国产专区欧美专区| 亚洲在线视频网站| 欧美一区二区三区四区在线 | 亚洲国产日韩一级| 男男成人高潮片免费网站| 亚洲最新在线视频| 亚洲欧美精品一区| 国产亚洲毛片| 亚洲国产精品尤物yw在线观看 | 亚洲一级片在线看| 国产在线高清精品| 欧美高清在线视频| 国产精品高清在线| 欧美mv日韩mv国产网站| 欧美三级电影网| 久久精品99久久香蕉国产色戒| 久久综合五月天婷婷伊人| 在线午夜精品自拍| 久久久久.com| 亚洲影视中文字幕| 麻豆精品视频| 欧美在线播放一区| 欧美激情国产日韩精品一区18| 欧美一区二区日韩| 欧美激情视频一区二区三区在线播放 | 红桃视频国产一区| 亚洲精选一区二区| 伊人狠狠色j香婷婷综合| 日韩视频专区| 亚洲人www| 欧美亚洲综合网| 亚洲一区二区黄色| 免费久久精品视频| 久久亚洲一区二区三区四区| 欧美人与禽猛交乱配| 欧美成人一区二区| 黄色成人在线网址| 亚洲欧美日韩精品久久久| 亚洲深夜激情| 欧美精品xxxxbbbb| 欧美大片一区二区| 精品91在线| 久久爱www久久做| 欧美影院午夜播放| 国产精品久久二区| 99在线精品免费视频九九视| 91久久久久久久久| 久热精品视频在线免费观看| 欧美在线你懂的| 国产精品欧美在线| 亚洲在线观看视频网站| 亚洲欧美日韩国产一区| 国产精品豆花视频| 一本色道久久综合狠狠躁篇的优点 | 欧美3dxxxxhd| 久热精品视频在线| 激情六月婷婷综合| 久久色在线播放| 蜜桃久久精品乱码一区二区| 黑人巨大精品欧美一区二区| 欧美一二三视频| 噜噜噜在线观看免费视频日韩| 黑丝一区二区三区| 久久精品国产清高在天天线 | 亚洲欧美另类国产| 国产精品色婷婷| 午夜久久美女| 麻豆亚洲精品| 亚洲裸体俱乐部裸体舞表演av| 欧美二区在线播放| 日韩一级在线| 性视频1819p久久| 国产综合在线看| 久久久精品久久久久| 免费在线观看日韩欧美| 日韩午夜在线| 国产精品久久久亚洲一区| 午夜久久久久久| 欧美大片免费看| 亚洲香蕉成视频在线观看| 国产欧美亚洲精品| 玖玖在线精品| 一区二区国产精品| 久久精品久久99精品久久| 在线高清一区| 欧美日韩成人在线播放| 亚洲一区二区三区国产| 美日韩精品免费观看视频| 99国内精品久久| 国产亚洲精品bv在线观看| 欧美大片在线看| 午夜亚洲伦理| 亚洲黄页一区| 欧美在线免费一级片| 亚洲精品欧美专区| 国产欧美一区二区三区国产幕精品 | 亚洲图片自拍偷拍| 美女被久久久| 午夜一区二区三视频在线观看| 亚洲丰满在线| 国产精品视频免费| 欧美精品在线免费| 欧美伊人久久久久久久久影院| 91久久精品久久国产性色也91| 欧美一级视频免费在线观看| 亚洲美女免费视频| 国内精品久久久久影院 日本资源| 欧美岛国在线观看| 久久久精品国产免费观看同学| 一区二区三区av| 亚洲国产一区二区三区a毛片| 久久久久国产精品麻豆ai换脸| av成人免费在线| 91久久久久久| 在线观看日韩av电影| 国产欧美日韩精品专区| 欧美日韩 国产精品| 欧美成人午夜77777| 久久高清国产| 欧美一区二区三区视频免费播放| 在线一区二区视频| 亚洲免费观看| 亚洲国内在线| 亚洲国产精品成人| 欧美国产先锋| 欧美α欧美αv大片| 久久综合九色综合久99| 久久久亚洲午夜电影| 久久久精品tv| 久久婷婷综合激情| 久久日韩粉嫩一区二区三区| 欧美在线不卡视频| 午夜久久福利| 午夜亚洲福利在线老司机| 亚洲一区综合| 欧美一级欧美一级在线播放| 香蕉成人伊视频在线观看| 亚洲欧洲99久久| 欧美一区二区三区另类 | 在线亚洲精品| 在线一区二区日韩| 亚洲一二三四区| 亚洲一区二区动漫| 欧美一区二区在线免费播放| 久久国产免费| 久久人人爽人人爽| 欧美国产日韩免费| 亚洲日韩欧美一区二区在线| 日韩视频免费看| 亚洲免费中文| 久久婷婷激情| 欧美福利在线| 欧美日韩精品一区二区在线播放 | 黄色亚洲在线| 亚洲黄色毛片| 一本色道久久88综合亚洲精品ⅰ | 亚洲日本欧美天堂| 亚洲新中文字幕| 久久www成人_看片免费不卡| 免费亚洲婷婷| 国产精品久久久久国产a级| 国产一区999| 亚洲国产综合在线| 亚洲影院高清在线| 久久最新视频| 亚洲免费观看在线观看| 欧美一区视频在线| 欧美福利视频一区| 国产伦精品一区二区三区四区免费| 好看的亚洲午夜视频在线| 在线中文字幕不卡| 久久这里有精品15一区二区三区| 91久久在线播放| 欧美在线网址| 欧美日韩亚洲高清一区二区| 国产亚洲欧美在线| 一本久久综合亚洲鲁鲁| 久久成人精品视频| 亚洲国产精品视频一区| 午夜精品一区二区三区电影天堂| 欧美成人一区二区| 国自产拍偷拍福利精品免费一| 一区二区三区国产精华| 老牛国产精品一区的观看方式| 99伊人成综合| 欧美第一黄网免费网站| 好吊一区二区三区| 欧美一区二区三区四区在线观看地址 | 中文网丁香综合网| 农村妇女精品| 久久精品72免费观看| 国产精品嫩草99a| 99伊人成综合|