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

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>
              久热精品在线| 美女视频黄 久久| 一区二区国产在线观看| 欧美日本亚洲| 亚洲免费视频在线观看| 亚洲欧美日韩一区在线| 国产欧美一区二区精品秋霞影院 | 欧美成ee人免费视频| 亚洲经典视频在线观看| 亚洲精品国产系列| 欧美日本簧片| 欧美专区在线观看一区| 久久久久91| 99视频精品免费观看| 亚洲已满18点击进入久久| 激情综合色丁香一区二区| 亚洲国产精品悠悠久久琪琪| 欧美日韩国产首页| 久久精品99国产精品日本| 久久久久国产精品一区| 夜夜嗨网站十八久久| 亚洲欧美精品一区| 亚洲国产精品久久精品怡红院 | 欧美一区激情视频在线观看| 欧美一级淫片播放口| 亚洲国产成人在线| 亚洲一区二区三区激情| 亚洲国产一区二区三区在线播| 亚洲破处大片| 国一区二区在线观看| 亚洲精品久久久久久下一站 | 国产精品xxxxx| 久久亚洲视频| 国产精品magnet| 欧美91大片| 国产精品色一区二区三区| 你懂的成人av| 国产亚洲a∨片在线观看| 亚洲乱码久久| 亚洲风情在线资源站| 亚洲欧美国产精品桃花| 亚洲最新视频在线播放| 久久久综合激的五月天| 欧美一区二区三区免费观看视频 | 先锋影音一区二区三区| 艳妇臀荡乳欲伦亚洲一区| 久久久精彩视频| 欧美一区二区免费视频| 欧美区亚洲区| 91久久久在线| 91久久亚洲| 久久躁日日躁aaaaxxxx| 久久久久久久久蜜桃| 国产精品久久久久天堂| 亚洲区第一页| 日韩午夜黄色| 欧美激情1区| 亚洲欧洲另类国产综合| 亚洲黄色影片| 毛片一区二区| 欧美电影在线| 亚洲区一区二| 欧美国产日产韩国视频| 亚洲国产裸拍裸体视频在线观看乱了中文 | 国产精品成人免费精品自在线观看| 欧美mv日韩mv国产网站| 永久免费精品影视网站| 久久久www成人免费毛片麻豆| 欧美在线亚洲一区| 国产欧美一区二区三区视频| 亚洲一区二区三区精品动漫| 亚洲欧美日韩国产成人精品影院| 欧美日韩免费一区二区三区视频| 亚洲精选91| 亚洲在线成人| 国产精品网站在线播放| 亚洲欧美国产日韩天堂区| 欧美在线视频a| 国产真实精品久久二三区| 欧美中文字幕视频在线观看| 久久久久久91香蕉国产| 影音欧美亚洲| 欧美刺激性大交免费视频| 亚洲人成高清| 亚洲欧美三级伦理| 国内一区二区三区| 欧美xxx成人| 中文av一区二区| 久久久综合视频| 亚洲精品资源美女情侣酒店| 欧美日韩不卡一区| 亚洲一区在线观看视频| 麻豆久久婷婷| 99天天综合性| 国产精品网站在线观看| 久久久蜜桃一区二区人| 亚洲三级网站| 久久久精品一区| 99在线精品视频在线观看| 国产精品卡一卡二卡三| 久久精品电影| 亚洲精品日产精品乱码不卡| 欧美一区免费| 99国产精品自拍| 韩日精品视频一区| 欧美精品三区| 欧美制服丝袜| 99视频精品全部免费在线| 久久久久久一区二区| 一区二区三区四区在线| 狠狠入ady亚洲精品| 欧美视频一区在线观看| 久久全球大尺度高清视频| 一区二区黄色| 亚洲国产日韩欧美一区二区三区| 午夜精品一区二区三区电影天堂| 亚洲第一综合天堂另类专| 国产精品系列在线| 欧美激情亚洲自拍| 久久精品视频在线播放| 在线亚洲电影| 亚洲精品视频在线播放| 欧美成人午夜| 久久综合色综合88| 久久激情婷婷| 午夜亚洲性色视频| 国产精品99久久久久久宅男 | 在线精品一区二区| 国产日本精品| 国产精品久久久对白| 欧美成人免费观看| 美国成人毛片| 久久一区二区三区av| 欧美一区二区三区视频免费播放| 日韩一级在线观看| 亚洲精品乱码久久久久| 欧美激情片在线观看| 麻豆成人综合网| 久久久久久久欧美精品| 香蕉成人久久| 午夜精品久久久久久久久久久久 | 伊人成人在线| 极品少妇一区二区| 国产自产在线视频一区 | 猛干欧美女孩| 蜜桃av综合| 欧美不卡一区| 欧美激情视频给我| 欧美久久电影| 欧美日韩国产在线播放网站| 欧美精品一区二区三区在线播放 | 久久久久国产精品麻豆ai换脸| 亚洲欧美综合一区| 性色av一区二区三区在线观看| 午夜精品一区二区三区四区| 午夜欧美视频| 久久久av网站| 欧美国产日韩一区二区三区| 欧美激情视频一区二区三区免费 | 伊人成人在线视频| 亚洲激情另类| 一本色道久久综合一区| 亚洲一区二区三区三| 欧美一级片一区| 久久人人97超碰国产公开结果| 牛牛精品成人免费视频| 亚洲国产一区视频| 亚洲一二三区在线观看| 欧美伊人久久久久久久久影院 | 午夜精品久久久久久久久久久久 | 欧美专区在线| 免费日韩一区二区| 欧美视频免费| 国内精品视频在线播放| 亚洲日本欧美日韩高观看| 一区二区三区你懂的| 久久久久久91香蕉国产| 亚洲国产精品一区二区久| 在线视频一区二区| 久久综合福利| 国产欧美激情| 亚洲免费观看高清在线观看| 欧美一区二区日韩一区二区| 女仆av观看一区| 一区二区三区四区在线| 久久亚洲二区| 国产精品女主播在线观看| 亚洲激情成人在线| 欧美一级大片在线免费观看| 亚洲电影av在线| 新狼窝色av性久久久久久| 欧美精品一区二区在线播放| 国产一区二区三区高清在线观看 | 亚洲一区二区三区精品在线| 开元免费观看欧美电视剧网站| 99综合在线| 欧美国产免费| 在线看片欧美| 久久久亚洲精品一区二区三区| 亚洲乱码久久|