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

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級(jí)} {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 夢(mèng)在天涯 閱讀(1654) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): STL/Boost

評(píng)論

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

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

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

  • 隨筆 - 461
  • 文章 - 4
  • 評(píng)論 - 746
  • 引用 - 0

常用鏈接

隨筆分類(lèi)

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1816487
  • 排名 - 5

最新評(píng)論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              亚洲国产精品一区二区久| 亚洲精品三级| 欧美中在线观看| 国产一区久久久| 欧美aⅴ99久久黑人专区| 美腿丝袜亚洲色图| 亚洲乱码久久| 亚洲天天影视| 国内久久精品视频| 91久久精品国产91久久性色| 欧美极品在线播放| 先锋影音国产精品| 久久久久久网| 美国十次了思思久久精品导航| 亚洲第一精品电影| 亚洲精品国产精品乱码不99按摩| 午夜亚洲一区| 亚洲电影免费观看高清完整版在线| 亚洲第一精品电影| 欧美亚洲不卡| 女主播福利一区| 欧美视频二区| 母乳一区在线观看| 欧美视频一区二区三区| 久久久久网址| 欧美日韩一区国产| 美女主播精品视频一二三四| 亚洲欧美日韩一区二区三区在线| 黄色成人av网| 一本色道婷婷久久欧美| 在线观看欧美黄色| 中文亚洲视频在线| 亚洲欧洲视频在线| 午夜精彩国产免费不卡不顿大片| 亚洲精品在线电影| 久久9热精品视频| 亚洲一二三四久久| 欧美成人性生活| 久久精视频免费在线久久完整在线看 | 老巨人导航500精品| 亚洲影院在线| 欧美高清不卡| 免费久久99精品国产自| 国产精品日韩欧美一区二区| 亚洲欧洲精品一区二区精品久久久| 国产日韩欧美另类| 一本一本a久久| 亚洲美女中文字幕| 美女在线一区二区| 久久女同互慰一区二区三区| 国产精品欧美日韩| 亚洲视频一区在线| 一本大道av伊人久久综合| 久久综合一区二区三区| 久久免费国产| 国内精品久久久久久| 亚洲欧美三级在线| 午夜在线视频一区二区区别| 欧美日韩国产一级片| 亚洲国产专区校园欧美| 亚洲高清在线观看| 噜噜噜久久亚洲精品国产品小说| 久久久久久精| 黄色工厂这里只有精品| 久久国产主播精品| 久久艳片www.17c.com| 黄色小说综合网站| 久久久国产亚洲精品| 麻豆成人精品| 亚洲国产精品黑人久久久| 久热精品视频在线观看| 欧美不卡视频一区| 亚洲欧洲视频在线| 欧美精品粉嫩高潮一区二区| 91久久午夜| 亚洲午夜精品久久久久久浪潮| 欧美日韩精品免费看| 中日韩午夜理伦电影免费| 亚洲欧美国产毛片在线| 国产精品手机视频| 欧美在线视频网站| 欧美成人一品| aa日韩免费精品视频一| 欧美午夜在线观看| 欧美自拍偷拍午夜视频| 欧美国产大片| 亚洲欧美日韩国产| 国内久久婷婷综合| 欧美成人精品在线| 亚洲天堂av图片| 久久久视频精品| 亚洲精品乱码久久久久久| 欧美日韩亚洲高清| 香蕉久久夜色精品国产使用方法| 快播亚洲色图| 亚洲婷婷在线| 合欧美一区二区三区| 欧美精品啪啪| 先锋资源久久| 亚洲人成网站在线播| 午夜精品久久久久99热蜜桃导演| 欧美性天天影院| 老牛国产精品一区的观看方式| 1024国产精品| 欧美性做爰猛烈叫床潮| 欧美中在线观看| 亚洲久久一区| 久久在线精品| 亚洲一本视频| 亚洲黄色免费| 国产欧美日韩一区| 欧美精品一区二区视频| 欧美一区二视频在线免费观看| 91久久夜色精品国产九色| 午夜精品理论片| 亚洲精品免费在线| 激情视频亚洲| 国产精品一区二区三区乱码| 欧美成人69av| 久久久九九九九| 亚洲一区二区三区在线| 亚洲黄一区二区三区| 久久视频一区二区| 新67194成人永久网站| 99在线热播精品免费99热| 伊人夜夜躁av伊人久久| 国产精品一卡| 国产精品国产三级国产普通话99 | 欧美日韩国内自拍| 久久久久网址| 欧美一区二区在线免费播放| 中文在线资源观看网站视频免费不卡 | 欧美电影免费观看| 久久精品视频在线看| 亚洲一区国产一区| 在线中文字幕一区| 日韩视频一区二区| 亚洲黄色大片| 亚洲国产精品www| 精品成人在线| 樱花yy私人影院亚洲| 国产在线精品自拍| 国产在线不卡视频| 国产欧美精品va在线观看| 国产精品午夜国产小视频| 欧美色精品天天在线观看视频 | 久久视频在线免费观看| 久久精品日产第一区二区三区| 欧美一区二区三区四区在线观看地址 | 99在线|亚洲一区二区| aⅴ色国产欧美| 亚洲色图在线视频| 亚洲一区国产一区| 西瓜成人精品人成网站| 性欧美18~19sex高清播放| 性色av香蕉一区二区| 久久国产精品久久久| 久久嫩草精品久久久久| 男人插女人欧美| 亚洲夫妻自拍| 一区二区三区国产| 欧美专区18| 欧美mv日韩mv国产网站| 欧美日韩国产成人在线91| 欧美天堂在线观看| 国产视频一区二区在线观看| 影音先锋亚洲视频| 亚洲伦理在线| 亚洲欧美精品一区| 久久久无码精品亚洲日韩按摩| 欧美激情欧美狂野欧美精品| 亚洲精品小视频| 午夜视频久久久久久| 麻豆国产精品777777在线| 欧美日韩精品免费看 | 麻豆精品精品国产自在97香蕉| 欧美成人资源| 国产麻豆视频精品| 亚洲风情亚aⅴ在线发布| 中文高清一区| 久久夜色精品一区| 一本一本久久a久久精品综合麻豆| 翔田千里一区二区| 欧美精品播放| 国产精品乱码人人做人人爱| 国模私拍一区二区三区| 亚洲午夜免费福利视频| 久久综合色88| 亚洲午夜日本在线观看| 麻豆av福利av久久av| 国产精品一区免费在线观看| 亚洲成人资源| 久久成人国产| 99国产一区| 欧美**人妖| 在线精品亚洲| 久久精品国产一区二区三区| 日韩一区二区电影网| 欧美成人黄色小视频| 国精品一区二区三区|