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

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电影| 国产精品美女久久福利网站| 亚洲一区二区高清| 亚洲欧美久久久久一区二区三区| 国产精品九色蝌蚪自拍| 欧美专区在线观看一区| 久久久久久色| aa国产精品| 亚洲欧美国产精品专区久久| 激情综合在线| 亚洲精品美女免费| 国产欧美精品xxxx另类| 欧美福利一区二区| 国产精品久久国产愉拍| 蜜臀av国产精品久久久久| 欧美精品日韩| 久久免费99精品久久久久久| 欧美成人午夜激情在线| 亚洲欧美日韩精品久久奇米色影视| 午夜一区在线| 一本久道久久综合中文字幕| 性欧美在线看片a免费观看| 亚洲黄色三级| 亚洲欧洲av一区二区| 亚洲激情视频在线| 亚洲欧美国产另类| 99re6这里只有精品视频在线观看| 亚洲视频1区| 91久久精品网| 久久爱www| 亚洲综合视频一区| 美女诱惑黄网站一区| 欧美一级二区| 欧美理论大片| 欧美大片网址| 好吊色欧美一区二区三区四区| 亚洲国产成人在线| 国产专区精品视频| 亚洲桃色在线一区| 日韩一级欧洲| 美女网站久久| 久久综合久久综合这里只有精品 | 欧美亚洲在线视频| 一本一本久久a久久精品综合麻豆| 欧美尤物一区| 先锋资源久久| 欧美天堂亚洲电影院在线观看 | 日韩一级精品| 久久综合久久久| 久久久综合网| 国产欧美一区二区三区沐欲| 亚洲蜜桃精久久久久久久| 亚洲激情影院| 久久久噜噜噜久久| 久久亚洲精品一区二区| 国内精品国产成人| 欧美一区成人| 久久精品一区| 黄色成人av网| 久久av一区二区三区漫画| 欧美尤物巨大精品爽| 国产精品乱子久久久久| 亚洲午夜免费视频| 翔田千里一区二区| 国产伦一区二区三区色一情| 亚洲一区二区3| 欧美伊人久久| 国产一区二区三区的电影 | 一区二区av在线| 亚洲视频网站在线观看| 国产精品成人一区二区网站软件 | 国内一区二区在线视频观看| 亚洲尤物精选| 久久欧美肥婆一二区| 黄网站色欧美视频| 开心色5月久久精品| 欧美国产一区在线| 99在线观看免费视频精品观看| 欧美精品一区二区在线观看| 亚洲精一区二区三区| 亚洲男人天堂2024| 国语自产在线不卡| 美女图片一区二区| 亚洲毛片在线看| 香蕉久久精品日日躁夜夜躁| 国产一区二区高清视频| 久热精品在线视频| 日韩视频在线观看一区二区| 欧美一区二区大片| 伊人狠狠色j香婷婷综合| 欧美成人一区在线| 亚洲在线观看视频| 免费在线观看成人av| 在线亚洲国产精品网站| 国产综合av| 欧美日本一区二区高清播放视频| 亚洲曰本av电影| 欧美国产第一页| 性欧美1819sex性高清| 极品少妇一区二区三区精品视频| 欧美国产一区二区| 小黄鸭视频精品导航| 欧美激情一区二区三区不卡| 午夜欧美精品久久久久久久| 亚洲福利在线观看| 国产精品你懂得| 欧美jizz19性欧美| 欧美亚洲综合在线| a91a精品视频在线观看| 美女主播精品视频一二三四| 亚洲一区欧美激情| 亚洲欧洲久久| 黄色成人精品网站| 国产精品人人爽人人做我的可爱| 久久先锋影音av| 亚洲欧美国产精品桃花| 亚洲精品乱码视频| 免费不卡欧美自拍视频| 欧美在线视频导航| 亚洲性人人天天夜夜摸| 亚洲精品欧美日韩| 伊人成人在线视频| 国产日韩欧美制服另类| 欧美日韩亚洲网| 欧美激情视频网站| 美女91精品| 久久免费视频在线| 久久国产精品久久久久久久久久| 在线亚洲成人| 一区二区电影免费在线观看| 亚洲高清一区二| 欧美激情一区二区三区蜜桃视频| 久久久久青草大香线综合精品| 亚洲女人天堂成人av在线| av成人免费在线| 亚洲日本中文字幕| 亚洲精品一级| 99视频超级精品| 一区二区电影免费观看| 日韩一二在线观看| 在线视频欧美日韩| 亚洲午夜精品一区二区三区他趣| 99国产精品国产精品久久| 99国产精品| 这里只有视频精品| 亚洲一区二区免费| 午夜精品成人在线| 欧美一区二区在线观看| 久久精品欧美日韩| 蜜桃久久av一区| 欧美大胆成人| 亚洲精品久久嫩草网站秘色| 亚洲精品社区| 亚洲午夜久久久| 欧美一级淫片播放口| 久久免费黄色| 欧美激情一二区| 国产精品高潮呻吟| 国产欧美一区二区精品秋霞影院| 国产区精品在线观看| 影音先锋久久资源网| 亚洲美女中出| 亚洲一区影院| 久久综合九色欧美综合狠狠| 亚洲电影在线观看| 亚洲视频中文字幕| 久久精品三级| 欧美日韩理论| 黄色成人av在线| 一区二区三区国产盗摄| 欧美伊久线香蕉线新在线| 美女91精品| 亚洲国产欧美一区二区三区同亚洲| 99在线精品免费视频九九视| 性久久久久久久| 欧美噜噜久久久xxx| 国产三级精品三级| 日韩一区二区免费看| 欧美伊人久久大香线蕉综合69| 欧美成人免费观看| 亚洲尤物影院| 欧美成人国产| 国产一区深夜福利| 欧美大胆人体视频| 一本久道久久综合中文字幕| 久久国产精品久久w女人spa| 欧美日韩视频在线一区二区 | 亚洲社区在线观看| 久久久久久亚洲精品不卡4k岛国| 亚洲激情视频网| 久久国产精品久久精品国产| 欧美日韩一区在线视频| 在线观看成人一级片| 欧美一级成年大片在线观看| 亚洲国产日韩综合一区| 久久精品视频在线看| 国产精品日韩在线播放| 一区二区三区你懂的|