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

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>
              久久亚洲精品一区| 欧美日韩免费在线视频| 欧美影院在线| 欧美日本久久| 国产欧美日韩综合一区在线播放| 国内精品视频一区| 欧美在线电影| 亚洲欧美三级在线| 国产日韩一区二区三区在线播放| 亚洲一区视频在线| 欧美高清一区| 蜜臀av国产精品久久久久| 国产综合久久久久久| 亚洲男人第一av网站| 亚洲一品av免费观看| 欧美日韩另类字幕中文| 亚洲成人在线视频播放| 榴莲视频成人在线观看| 久久久久久久91| 亚洲国产清纯| 亚洲国产欧美另类丝袜| 欧美日韩国产一区| 亚洲人成小说网站色在线| 久久久一区二区| 久久免费视频在线观看| 亚洲黄色免费| 亚洲精品视频在线看| 国产精品美女主播在线观看纯欲| 欧美一区激情| 久久综合色综合88| 99国产精品国产精品久久| 亚洲深夜av| 国产一区二区精品久久99| 欧美激情日韩| 国产精品久久久久久av下载红粉 | 久久人人97超碰国产公开结果| 欧美在线黄色| 亚洲精品视频在线| 午夜视频在线观看一区| 黑人巨大精品欧美黑白配亚洲| 亚洲国产天堂久久综合网| 国产精品成人一区二区网站软件| 亚洲一区二区三区免费观看| 欧美在现视频| 亚洲一二三区精品| 噜噜噜在线观看免费视频日韩 | 欧美一区二区日韩| 亚洲精品免费观看| 欧美一区国产在线| 亚洲图片欧美日产| 在线视频你懂得一区二区三区| 国产精品国产三级国产专播品爱网 | 快播亚洲色图| 一本一本大道香蕉久在线精品| 亚洲欧美国产精品专区久久| 亚洲国产欧美一区二区三区久久| 亚洲一区在线观看视频 | 欧美日本三级| 美女性感视频久久久| 国产精品草草| 亚洲第一福利在线观看| 国产精品第一区| 久久国产精品99国产| 美女诱惑一区| 免费欧美网站| 国产精品久久久久9999高清 | 国产情人节一区| 一区二区三区不卡视频在线观看| 亚洲国产精品成人精品| 欧美一级久久久久久久大片| 性久久久久久久久久久久| 欧美日韩日本网| 亚洲黄色视屏| 99精品久久| 欧美激情精品久久久久久蜜臀 | 欧美福利在线| 欧美综合77777色婷婷| 欧美性生交xxxxx久久久| 亚洲人成网站影音先锋播放| 亚洲国内精品在线| 免费成人黄色av| 欧美第十八页| 一本久久知道综合久久| 亚洲视屏一区| 欧美日韩精品在线观看| 亚洲精品影视| 亚洲午夜视频在线观看| 蜜桃av一区二区在线观看| 欧美国产第一页| 一本色道综合亚洲| 欧美日韩在线视频一区| 亚洲婷婷免费| 久久美女性网| 亚洲欧洲一区二区三区在线观看| 久热精品视频| 亚洲高清视频一区| 欧美亚洲一区二区在线| 国产精品乱码久久久久久| 久久久www成人免费毛片麻豆| 免费在线欧美视频| 亚洲一级在线| 国产亚洲精品久久飘花| 欧美一区二区三区在线观看视频 | 国产精品日韩高清| 久久乐国产精品| 91久久精品国产91性色 | 欧美日韩一区综合| 久久久久久91香蕉国产| 亚洲精品国产系列| 久久尤物电影视频在线观看| 亚洲另类一区二区| 欧美揉bbbbb揉bbbbb| 欧美一区二区三区在线免费观看| 久久久久网站| 亚洲欧美日韩综合一区| 有码中文亚洲精品| 国产欧美在线| 欧美激情按摩在线| 久久婷婷国产综合精品青草| 日韩一二在线观看| 蜜臀av性久久久久蜜臀aⅴ| 一本色道久久综合亚洲91 | 美腿丝袜亚洲色图| 久久久久九九九九| 亚洲欧美中日韩| 亚洲国产精品激情在线观看| 狠狠久久婷婷| 欧美性色aⅴ视频一区日韩精品| 欧美激情第9页| 久久久精品国产99久久精品芒果| 亚洲欧美福利一区二区| 91久久综合亚洲鲁鲁五月天| 欧美黄色视屏| 久久夜色精品国产| 久久精品国产一区二区三| 中文在线不卡视频| 日韩一级黄色大片| 亚洲国产日韩一区| 在线国产欧美| 尤物在线观看一区| 亚洲国产一区二区三区青草影视| 国产美女扒开尿口久久久| 一区二区三区日韩欧美精品| 99热免费精品在线观看| 亚洲高清资源| 亚洲精品社区| 最近中文字幕mv在线一区二区三区四区| 久久av一区二区三区漫画| 夜夜嗨av一区二区三区中文字幕| 亚洲永久字幕| 亚洲一级黄色| 亚洲一二三四区| 亚洲视频精选| av成人国产| 亚洲精品综合久久中文字幕| 亚洲国产毛片完整版| 亚洲国产日韩在线| 一本色道久久综合亚洲精品婷婷| 亚洲人永久免费| 亚洲午夜精品一区二区三区他趣 | 在线成人av网站| 亚洲精品国产精品久久清纯直播| 一区二区三区中文在线观看| 亚洲欧洲另类国产综合| 亚洲欧洲日本mm| 亚洲嫩草精品久久| 欧美有码视频| 久久国内精品视频| 久久久久综合网| 久久久久久久一区| 欧美高清视频在线| 久久躁狠狠躁夜夜爽| 亚洲人线精品午夜| 亚洲国产成人一区| 亚洲欧美精品一区| 欧美影院精品一区| 欧美色区777第一页| 国产精品女人毛片| 激情综合色综合久久| 在线观看日韩av| 亚洲三级观看| 亚洲午夜三级在线| 久久艳片www.17c.com| 亚洲国产国产亚洲一二三| 99视频有精品| 久久精品91| 欧美国产日韩在线| 国产精品啊啊啊| 国产精品免费网站在线观看| 亚洲精品123区| 亚洲欧美另类中文字幕| 久久影院午夜片一区| 欧美激情2020午夜免费观看| 一区二区三区高清在线观看| 久久er99精品| 欧美午夜大胆人体| 精品88久久久久88久久久| 国产精品99久久久久久久vr| 久久亚洲不卡| 亚洲少妇最新在线视频|