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

C++ Programmer's Cookbook

{C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

stl-什么時候用那種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 夢在天涯 閱讀(1643) 評論(1)  編輯 收藏 引用 所屬分類: STL/Boost

評論

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

Effective STL Item One is also helpful.  回復  更多評論   

公告

EMail:itech001#126.com

導航

統計

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1811754
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              久久成人久久爱| 一区二区三区四区蜜桃| 欧美与欧洲交xxxx免费观看| 亚洲一区二区三区高清不卡| 国产精品免费视频xxxx| 久久久精品国产免大香伊| 欧美中文字幕不卡| 亚洲国产日韩一区| 亚洲欧洲美洲综合色网| 欧美人与禽猛交乱配| 亚洲自拍偷拍色片视频| 午夜精品视频在线观看| 黄色一区二区在线观看| 亚洲电影免费观看高清完整版在线| 欧美精品免费观看二区| 欧美亚洲一区二区三区| 久久精品国产精品亚洲精品| 亚洲精品视频一区| 亚洲制服av| 亚洲精品一区二区三区福利| 亚洲资源在线观看| 亚洲国产婷婷香蕉久久久久久99| 亚洲精品色图| 激情久久影院| 亚洲看片网站| 精品69视频一区二区三区| 日韩亚洲欧美在线观看| 激情婷婷亚洲| 亚洲网站视频福利| 亚洲日本成人在线观看| 午夜视频一区在线观看| 99视频精品全国免费| 久久成人免费视频| 亚洲欧美激情一区二区| 欧美不卡视频| 久久综合狠狠综合久久综合88| 欧美日韩播放| 欧美激情国产日韩精品一区18| 国产精品美女诱惑| 亚洲国产欧美在线人成| 激情久久久久久久| 亚洲欧美一区在线| 中文精品99久久国产香蕉| 久久综合色综合88| 久久久国产成人精品| 欧美性大战久久久久| 欧美国产三区| 亚洲国产精品99久久久久久久久| 亚洲一区二区三区四区视频| 一区二区三区产品免费精品久久75| 久久精品亚洲精品| 久久精品水蜜桃av综合天堂| 国产精品高潮呻吟视频| 亚洲精品色婷婷福利天堂| 亚洲国产成人av| 久久久久久久精| 久久精品国产精品| 国产午夜精品一区二区三区视频| av成人黄色| 亚洲一区二区视频在线| 欧美人在线观看| 亚洲精品婷婷| 一区二区三区国产盗摄| 欧美精品一区二区三| 亚洲欧洲在线看| 一区二区三区国产在线观看| 欧美日韩喷水| 一本色道久久综合狠狠躁篇怎么玩| av72成人在线| 国产精品xxxxx| 亚洲午夜精品一区二区| 性久久久久久| 国产日韩欧美一区二区三区在线观看 | 亚洲欧美日韩一区二区三区在线 | 亚洲欧美影院| 久久精品视频导航| 精品动漫一区| 欧美高清视频www夜色资源网| 亚洲电影免费在线观看| 亚洲免费大片| 欧美亚州韩日在线看免费版国语版| 99re6热在线精品视频播放速度 | 国产一区二区三区成人欧美日韩在线观看| 亚洲欧美国产高清| 久久夜色精品一区| 亚洲国产精品毛片| 欧美精品一区二区三区蜜臀| 夜夜狂射影院欧美极品| 欧美在现视频| 亚洲人成人一区二区在线观看| 欧美精品一区二区在线播放| 亚洲一区二区3| 免费高清在线视频一区·| 亚洲美女视频在线观看| 国产精品少妇自拍| 久久综合网hezyo| 一区二区三区国产在线| 久久天天狠狠| 一本一本a久久| 国产色产综合产在线视频| 老妇喷水一区二区三区| 一区二区三区高清| 免费国产一区二区| 亚洲欧美日韩另类精品一区二区三区 | 午夜精品福利视频| 亚洲二区视频| 久久久九九九九| 999亚洲国产精| 狠狠色狠色综合曰曰| 欧美日韩一区二区三区在线观看免| 欧美在线日韩| 中文亚洲免费| 亚洲大片精品永久免费| 欧美自拍丝袜亚洲| 宅男噜噜噜66国产日韩在线观看| 国产情侣一区| 国产精品h在线观看| 欧美成人免费全部| 久久精品男女| 亚洲一区二区三区精品在线观看 | 亚洲精品久久久久久下一站| 久久午夜国产精品| 午夜精品一区二区三区四区| 亚洲九九九在线观看| 在线视频观看日韩| 黄色综合网站| 国产欧美一区视频| 国产精品永久免费| 国产精品福利在线| 欧美日韩免费一区二区三区| 欧美激情小视频| 免费亚洲一区| 免费成人黄色片| 老鸭窝毛片一区二区三区| 久久精品av麻豆的观看方式 | 亚洲国产小视频在线观看| 免费视频亚洲| 久久综合伊人| 麻豆精品精华液| 麻豆国产精品一区二区三区 | 久久国内精品自在自线400部| 亚洲性视频网址| 亚洲一级影院| 亚洲欧美精品suv| 性做久久久久久久久| 欧美一区=区| 久久精彩视频| 久久在线视频| 欧美福利视频| 亚洲激情电影在线| 亚洲精品在线免费| 一区二区三区高清不卡| 亚洲视频在线一区观看| 亚洲欧美日韩一区二区三区在线| 亚洲女同精品视频| 久久国产精品久久国产精品| 久久亚洲精选| 欧美大尺度在线| 国产精品videossex久久发布| 国产精品盗摄久久久| 国产午夜精品美女毛片视频| 在线日韩av片| 亚洲视频一区二区在线观看| 午夜精品久久久久久久久久久久久 | 久久久国产精品一区| 欧美va日韩va| 亚洲麻豆av| 亚洲欧美激情四射在线日 | 亚洲人成毛片在线播放女女| av成人免费| 久久久久久9| 欧美日韩大片| 国户精品久久久久久久久久久不卡| 国语精品中文字幕| 99ri日韩精品视频| 久久久久久久97| 亚洲精品国产视频| 亚洲欧美影院| 欧美另类一区| 黄色成人91| 亚洲手机视频| 欧美高清你懂得| 欧美亚洲视频| 欧美日韩一区二区三区在线看 | 欧美日韩中文另类| 影音先锋中文字幕一区二区| 亚洲深夜福利网站| 欧美本精品男人aⅴ天堂| 亚洲无亚洲人成网站77777| 久久视频一区| 国产日本亚洲高清| 在线中文字幕一区| 欧美激情视频一区二区三区不卡| 中文亚洲视频在线| 欧美精品日韩综合在线| 国语自产精品视频在线看| 亚洲欧美日本日韩| 亚洲人成啪啪网站| 久久综合久久综合九色| 国产亚洲欧洲一区高清在线观看|