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

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>
              一本久道久久综合婷婷鲸鱼| 夜夜嗨av一区二区三区四季av | 99国产精品视频免费观看一公开 | 久久综合国产精品台湾中文娱乐网| 国产亚洲成人一区| 久久av一区二区| 欧美电影在线免费观看网站| 亚洲精品乱码| 国产精品久久久久久av下载红粉 | 欧美日韩精品久久| 亚洲自拍16p| 麻豆av一区二区三区久久| 亚洲国产午夜| 国产精品jizz在线观看美国| 欧美一级大片在线免费观看| 亚洲电影观看| 亚洲深夜福利视频| 国产一区二区三区精品久久久| 久久视频在线看| 99亚洲视频| 久久久亚洲高清| 在线一区二区三区四区五区| 国产亚洲人成网站在线观看| 欧美成人精品1314www| 亚洲在线中文字幕| 欧美激情精品久久久久久黑人 | 蜜臀a∨国产成人精品| 一区二区三区国产在线| 国产视频一区在线观看| 米奇777超碰欧美日韩亚洲| 夜夜嗨av一区二区三区网页| 久久综合色一综合色88| 夜夜爽av福利精品导航 | 亚洲宅男天堂在线观看无病毒| 米奇777超碰欧美日韩亚洲| 亚洲性图久久| 亚洲精品美女久久7777777| 国产精品一区二区三区乱码 | 麻豆成人在线| 亚洲欧美在线免费观看| 亚洲三级性片| 狠狠做深爱婷婷久久综合一区 | 欧美在线观看一区二区| 日韩视频精品在线观看| 韩日成人av| 国产精品午夜在线| 欧美片第一页| 美女精品网站| 久久国产一区二区| 亚洲欧美日韩精品久久亚洲区| 亚洲日本视频| 亚洲承认在线| 老司机精品视频网站| 欧美在线日韩| 午夜精品久久久久久99热| 亚洲精品视频中文字幕| 亚洲国产高清在线观看视频| 国产综合第一页| 国产情人综合久久777777| 国产精品伦子伦免费视频| 欧美日韩日本网| 欧美日韩精品在线播放| 欧美精品国产一区| 欧美激情aⅴ一区二区三区 | 欧美日韩精品一区| 欧美激情一二区| 欧美激情一区二区三区在线视频| 裸体素人女欧美日韩| 久久久久久夜| 鲁鲁狠狠狠7777一区二区| 久久久久久亚洲精品中文字幕 | 欧美激情精品久久久久久免费印度| 久久人人九九| 欧美v日韩v国产v| 麻豆国产精品va在线观看不卡| 久久久久久久久蜜桃| 久久人体大胆视频| 欧美成人高清| 欧美日韩免费一区二区三区视频| 欧美另类高清视频在线| 欧美日韩国产大片| 欧美偷拍一区二区| 国产精品日韩在线播放| 国产亚洲一区二区三区在线观看| 韩国精品一区二区三区| 在线观看免费视频综合| 亚洲毛片在线免费观看| 一区二区三区黄色| 欧美一区二区三区免费大片| 久久久久网站| 亚洲高清123| 亚洲乱码精品一二三四区日韩在线| 亚洲精品人人| 亚洲在线一区| 久久国产欧美| 欧美理论电影在线观看| 国产精品久久久久影院亚瑟| 国模精品一区二区三区| 亚洲国产影院| 亚洲欧美日韩一区二区三区在线| 久久精品国产一区二区三| 欧美电影打屁股sp| 99re这里只有精品6| 午夜精品免费视频| 欧美sm视频| 国产精品欧美风情| 在线成人中文字幕| 中文久久精品| 麻豆乱码国产一区二区三区| 亚洲黄色在线观看| 亚洲欧美日韩在线播放| 葵司免费一区二区三区四区五区| 欧美精品一卡二卡| 国产视频一区二区在线观看| 亚洲精品黄色| 久久精品女人天堂| av成人老司机| 狼狼综合久久久久综合网| 国产精品成人一区二区三区夜夜夜 | 亚洲午夜精品视频| 女人天堂亚洲aⅴ在线观看| 国产精品久久久久久影视| 亚洲国产精品黑人久久久| 羞羞漫画18久久大片| 亚洲人成艺术| 久久精品日产第一区二区| 欧美午夜精品理论片a级按摩 | 亚洲黄色免费网站| 欧美一区久久| 国产精品s色| 日韩视频免费| 男同欧美伦乱| 欧美在线二区| 国产精品久久久久久久电影| 亚洲靠逼com| 免费在线亚洲| 久久精品一区二区| 国产午夜精品久久久久久久| 日韩亚洲欧美一区二区三区| 另类激情亚洲| 午夜精品短视频| 国产精品久久久久久久一区探花 | 久色婷婷小香蕉久久| 国产午夜精品一区二区三区视频| 在线视频欧美精品| 亚洲激情婷婷| 欧美**字幕| 亚洲国产美国国产综合一区二区| 久久成人精品视频| 亚洲综合国产精品| 国产精品一区二区久久精品| 亚洲视频在线免费观看| 亚洲人线精品午夜| 欧美~级网站不卡| 尤物精品国产第一福利三区 | 亚洲电影激情视频网站| 久久久综合免费视频| 国内欧美视频一区二区| 久久久精品动漫| 欧美中文字幕视频| 国产资源精品在线观看| 久久精品最新地址| 久久精品国产77777蜜臀| 韩国美女久久| 欧美a级大片| 欧美福利视频网站| 9久草视频在线视频精品| 亚洲美女91| 国产精品白丝jk黑袜喷水| 午夜精品福利在线观看| 亚洲欧美日韩在线播放| 国内精品视频在线观看| 欧美jizz19hd性欧美| 蜜桃精品久久久久久久免费影院| 最新国产乱人伦偷精品免费网站 | 日韩午夜av| 国产精品毛片va一区二区三区| 亚洲欧美日韩在线观看a三区| 亚洲夜间福利| 国内成+人亚洲| 欧美电影免费观看| 欧美激情精品久久久久久大尺度| 一区二区三区久久久| 亚洲午夜电影在线观看| 国产午夜精品理论片a级探花| 久久躁狠狠躁夜夜爽| 美女视频网站黄色亚洲| 日韩一区二区免费高清| 在线亚洲欧美专区二区| 国产日本欧美一区二区三区| 蜜桃精品一区二区三区| 欧美激情一级片一区二区| 午夜久久久久久久久久一区二区| 久久狠狠婷婷| 99在线观看免费视频精品观看| 一区二区冒白浆视频| 国产日产亚洲精品| 亚洲国产婷婷| 国产欧美精品久久| 亚洲丰满少妇videoshd|