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

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>
              欧美一区二区三区四区视频| 中日韩视频在线观看| 久久综合精品一区| 久久九九免费| 久久亚洲色图| 欧美成人免费视频| 欧美成人免费全部| 欧美视频精品一区| 国产伦精品一区二区三区免费迷| 国产私拍一区| 精品91在线| 99国产麻豆精品| 亚洲欧美日韩第一区| 久久久精品一品道一区| 免费视频久久| 亚洲电影自拍| 亚洲精品韩国| 欧美一区二区三区免费看| 久久久久久一区二区三区| 欧美激情第六页| 欧美午夜电影在线观看| 激情欧美一区| 亚洲资源在线观看| 欧美1区3d| 亚洲综合日韩| 欧美精品二区三区四区免费看视频| 国产精品第三页| 亚洲国产欧美日韩另类综合| 亚洲欧美日韩第一区| 欧美不卡在线| 西瓜成人精品人成网站| 欧美激情偷拍| 精品成人一区二区| 久久精品亚洲一区二区| 欧美激情久久久| 亚洲欧美日韩视频二区| 欧美va日韩va| 狠狠狠色丁香婷婷综合激情| 亚洲一区二区三区在线看| 男女激情视频一区| 香蕉久久夜色| 国产精品黄页免费高清在线观看| 亚洲国内精品| 久久综合图片| 欧美一区二区在线观看| 国产精品久久久久久久7电影| 亚洲黄色免费网站| 久久午夜影视| 欧美一区二区三区电影在线观看| 国产精品高潮呻吟久久| 亚洲乱码国产乱码精品精可以看| 久久午夜视频| 久久黄色级2电影| 国产日韩欧美二区| 欧美一区二区三区视频免费播放| 一区二区久久久久| 欧美日韩在线高清| 一本一道久久综合狠狠老精东影业| 男女精品网站| 久久久久天天天天| 一区二区三区亚洲| 狂野欧美性猛交xxxx巴西| 欧美在线在线| 在线播放中文字幕一区| 久久亚洲一区二区三区四区| 欧美在线视频在线播放完整版免费观看| 欧美丝袜一区二区| 亚洲欧美综合国产精品一区| 这里只有精品丝袜| 国产精品亚洲综合| 久久久久这里只有精品| 久久九九99| 亚洲国产成人av| 亚洲高清在线| 欧美日韩福利| 亚洲欧美综合v| 久久精品亚洲一区二区三区浴池 | 欧美日本中文字幕| 亚洲欧洲午夜| 亚洲免费观看高清在线观看 | 在线精品视频在线观看高清 | 久久国产精品72免费观看| 国产原创一区二区| 欧美成人国产va精品日本一级| 男人的天堂成人在线| 亚洲精品少妇30p| 日韩一级片网址| 国产精品日本精品| 久久夜色精品国产| 欧美激情一二三区| 久久精品免费电影| 国产精品视频xxxx| 亚洲欧美日韩另类精品一区二区三区| 亚洲视频在线一区| 国内精品美女在线观看| 亚洲国产免费看| 欧美日韩在线播放三区四区| 久久久精品网| 欧美日韩精品中文字幕| 欧美在线免费播放| 欧美成人精品一区二区三区| 亚洲自拍偷拍麻豆| 久久国产精品一区二区三区| 亚洲精选久久| 欧美一级专区| 亚洲一二三级电影| 欧美 日韩 国产 一区| 亚洲欧美日韩国产综合精品二区| 久久天天躁狠狠躁夜夜爽蜜月| 亚洲夜间福利| 欧美精品在线免费播放| 久久久亚洲人| 国产精品国产一区二区| 亚洲福利av| 激情综合激情| 亚洲影院高清在线| 日韩视频精品在线| 久久久久久一区二区三区| 欧美影院在线| 国产精品毛片在线| 99精品欧美一区| 一区二区三区|亚洲午夜| 另类国产ts人妖高潮视频| 欧美在线国产| 国产精品久久久久久久app| 日韩亚洲在线| 亚洲美女中文字幕| 欧美v亚洲v综合ⅴ国产v| 老司机午夜精品| 国模一区二区三区| 性色av一区二区三区在线观看 | 91久久久久久| 久久精品欧美日韩| 久久精品人人做人人综合| 欧美日韩精品一区二区在线播放 | 国产精品久久精品日日| 亚洲日韩中文字幕在线播放| 亚洲国产99| 久久久久久久久久看片| 欧美在线视频日韩| 国产欧美日韩亚州综合| 亚洲美女精品成人在线视频| 午夜国产欧美理论在线播放| 亚洲神马久久| 欧美日韩一区在线观看视频| 亚洲欧洲日本mm| 尤物精品在线| 老司机午夜免费精品视频| 欧美成人激情在线| 1024精品一区二区三区| 久久精品人人做人人综合| 久久在线免费观看视频| 国产精品99久久久久久久久久久久| 欧美日韩国产在线播放| 日韩视频在线永久播放| 一区二区三区免费在线观看| 欧美日韩一区二区三区免费看| 亚洲美女毛片| 香蕉av福利精品导航| 99国产精品一区| 亚洲影院色无极综合| 国产午夜精品久久| 久久电影一区| 欧美高清在线一区| a4yy欧美一区二区三区| 欧美日韩一区三区四区| 午夜精品国产精品大乳美女| 久久久久久久一区| 影音先锋中文字幕一区| 久久一区二区三区四区| 欧美成人在线网站| 亚洲色图在线视频| 国产精品制服诱惑| 久久成人精品| 老牛嫩草一区二区三区日本| 亚洲精品久久久久久下一站| 欧美日韩亚洲三区| 亚洲免费人成在线视频观看| 美女视频黄免费的久久| 亚洲一区在线看| 黑人操亚洲美女惩罚| 欧美超级免费视 在线| 亚洲午夜国产一区99re久久 | 国产一区二区三区在线免费观看 | 亚洲国产影院| 亚洲欧美日韩网| 在线欧美日韩精品| 欧美日韩一区二区三区免费| 久久蜜桃精品| 校园春色国产精品| 亚洲欧洲在线一区| 久久不射电影网| 亚洲一区二区三区视频| 91久久久久久久久| 国产真实乱子伦精品视频| 国产精品久久久久国产精品日日 | 国内精品久久久| 国产精品久久久一区麻豆最新章节 | 国产酒店精品激情| 欧美日韩a区|