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

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>
              免费欧美视频| 亚洲精品一区二区在线观看| 国产精品99久久久久久久vr| 欧美日韩卡一卡二| 亚洲性视频网址| 亚洲视频在线观看网站| 国产精品老牛| 久久国产精品亚洲77777| 欧美一区视频在线| 黄色另类av| 欧美激情一区三区| 欧美视频在线观看免费| 欧美一区二区精品在线| 欧美影片第一页| 亚洲国产日韩欧美在线图片| 亚洲激精日韩激精欧美精品| 免费在线亚洲欧美| 亚洲一线二线三线久久久| 中国女人久久久| 国产一区二区电影在线观看 | 国产日韩欧美视频在线| 久久av最新网址| 久久综合狠狠综合久久综青草| 亚洲黄色在线看| 99综合精品| 狠狠色噜噜狠狠色综合久| 91久久精品一区| 国产日韩欧美一区在线| 欧美风情在线| 国产精品一区三区| 亚洲高清123| 国产情人综合久久777777| 欧美福利一区| 国产精品中文字幕在线观看| 欧美国产日韩精品| 国产精品网红福利| 亚洲国产美女久久久久| 国产精品一区二区a| 亚洲国产精品第一区二区 | 欧美夜福利tv在线| 99在线热播精品免费99热| 性xx色xx综合久久久xx| 亚洲精品中文字幕在线| 欧美在线视频免费观看| 亚洲专区在线| 欧美精品免费看| 免费永久网站黄欧美| 国产精品一区二区男女羞羞无遮挡| 欧美国产三区| 在线精品视频免费观看| 性色一区二区| 午夜精品影院在线观看| 欧美日韩国产在线| 亚洲国产精品尤物yw在线观看| 国产一区视频在线看| 亚洲一区二区三区四区中文| 一区二区三区四区在线| 欧美成人精品1314www| 久久综合给合久久狠狠色| 国产精品一区二区三区久久| 一本色道久久| 亚洲午夜精品久久| 欧美成人午夜激情在线| 欧美国产精品人人做人人爱| 国自产拍偷拍福利精品免费一| 亚洲综合日韩在线| 性xx色xx综合久久久xx| 国产精品videosex极品| 一本色道**综合亚洲精品蜜桃冫| 夜夜爽av福利精品导航| 欧美日本高清视频| 日韩一区二区久久| 亚洲欧美激情诱惑| 国产精品羞羞答答xxdd| 欧美一级久久久| 久久精品国产一区二区三| 国产日韩欧美高清| 久久久久久9| 欧美成人免费在线观看| 亚洲日本中文字幕| 欧美另类变人与禽xxxxx| 日韩亚洲不卡在线| 性欧美暴力猛交另类hd| 国产精品一区二区你懂的| 欧美一级二级三级蜜桃| 嫩草伊人久久精品少妇av杨幂| 在线日韩一区二区| 欧美黄色精品| 亚洲午夜在线视频| 久久久午夜视频| 亚洲久久成人| 国产精品视频一区二区高潮| 欧美影院在线| 亚洲国产第一| 亚洲欧美在线磁力| 精品成人国产| 欧美日韩日本国产亚洲在线| 亚洲视频一区在线| 老司机精品久久| 一区二区三区欧美激情| 国产欧美在线视频| 欧美成人综合一区| 亚洲一区二区在线看| 看欧美日韩国产| 亚洲无人区一区| 狠狠色丁香久久婷婷综合_中| 免费人成精品欧美精品| 亚洲视频一二| 亚洲第一区在线观看| 亚洲免费在线视频一区 二区| 狠狠色噜噜狠狠色综合久| 欧美日韩成人综合天天影院| 亚洲欧美区自拍先锋| 91久久综合| 久久久综合精品| 亚洲一区久久| 亚洲区国产区| 狠狠色综合播放一区二区| 欧美视频一区| 免费中文日韩| 久久九九99视频| 亚洲一区二区三区色| 亚洲欧洲另类国产综合| 久久在线免费| 欧美在线首页| 亚洲在线中文字幕| 亚洲美女免费精品视频在线观看| 国产在线国偷精品产拍免费yy| 欧美日韩精品系列| 欧美96在线丨欧| 久久偷窥视频| 欧美与黑人午夜性猛交久久久| 制服诱惑一区二区| 日韩视频在线一区二区| 亚洲国产精品精华液2区45 | 亚洲第一综合天堂另类专| 国产精品电影在线观看| 欧美伦理91i| 欧美国产日韩一区二区在线观看| 久久精品视频在线| 久久成人精品无人区| 亚洲影音一区| 亚洲你懂的在线视频| 99在线精品视频在线观看| 亚洲人久久久| 亚洲蜜桃精久久久久久久 | 午夜精品福利一区二区三区av | 黄色一区二区在线| 国内成人精品视频| 国内欧美视频一区二区| 国产一区二区三区四区老人| 国产美女扒开尿口久久久| 国产精品视频一二三| 国产精品人人爽人人做我的可爱 | 欧美精品一区二区三区视频| 免费久久99精品国产| 久久综合久久久久88| 免费不卡在线观看av| 欧美激情视频一区二区三区在线播放 | 亚洲精品一区二区三区四区高清| 亚洲电影下载| 9l视频自拍蝌蚪9l视频成人| 国产精品99久久久久久有的能看| 亚洲网站在线看| 欧美一区二区三区免费观看 | 亚洲日本电影在线| 亚洲每日在线| 亚洲一区二区毛片| 久久国产精品99精品国产| 久久综合成人精品亚洲另类欧美| 免费在线欧美视频| 亚洲人成在线播放| 亚洲视频1区2区| 久久精品亚洲乱码伦伦中文| 欧美成年网站| 国产乱码精品一区二区三区五月婷| 国产一区二区三区久久悠悠色av| 亚洲国产91精品在线观看| 一区二区三区国产| 久久国产精品久久精品国产| 免费一区视频| 亚洲一区二区久久| 美女免费视频一区| 国产精品人成在线观看免费| 狠狠综合久久| 亚洲一区二区av电影| 裸体素人女欧美日韩| 日韩一级在线观看| 久久精品国产96久久久香蕉| 欧美精品综合| 永久91嫩草亚洲精品人人| 亚洲视屏一区| 欧美肥婆bbw| 欧美一级播放| 欧美日韩系列| 亚洲人午夜精品免费| 久久久久99| 中文在线一区| 欧美日韩成人综合在线一区二区| 好吊妞**欧美|