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

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級} {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 夢在天涯 閱讀(1643) 評論(1)  編輯 收藏 引用 所屬分類: STL/Boost

評論

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

Effective STL Item One is also helpful.  回復(fù)  更多評論   

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

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

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1811750
  • 排名 - 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福利在线观看| 亚洲免费观看高清完整版在线观看熊| 久久夜色精品国产| 亚洲片在线观看| 999在线观看精品免费不卡网站| 欧美日韩理论| 欧美一区免费| 久久久免费观看视频| 亚洲精品乱码久久久久| 日韩系列欧美系列| 国产一区在线播放| 亚洲国产91精品在线观看| 欧美高清视频一区| 欧美一区二区视频在线观看| 久久成年人视频| 亚洲最黄网站| 欧美在线视频一区二区| 亚洲人成网站777色婷婷| 一区二区三区视频在线| 国内精品美女av在线播放| 91久久精品国产| 国产免费亚洲高清| 亚洲黄一区二区| 国产亚洲欧美日韩在线一区| 91久久国产综合久久蜜月精品| 国产精品海角社区在线观看| 免费亚洲一区| 国产精品亚洲аv天堂网| 欧美国产亚洲视频| 国产午夜精品理论片a级探花| 亚洲国产欧美一区二区三区久久 | 久久黄色网页| 亚洲午夜精品福利| 免费久久久一本精品久久区| 欧美在线三级| 欧美日韩午夜| 欧美激情性爽国产精品17p| 国产毛片久久| 在线亚洲精品福利网址导航| 亚洲欧洲日本专区| 久久国产精品99久久久久久老狼| 夜夜嗨av一区二区三区四区| 久久久久88色偷偷免费| 久久成人亚洲| 国产精品日韩欧美一区二区| 亚洲精品一区二区三| 亚洲国产欧美在线| 久久综合色综合88| 美女国产一区| 一区二区三区在线观看国产| 午夜久久美女| 欧美一区二区三区喷汁尤物| 国产精品二区影院| 一区二区三区成人精品| 在线综合亚洲| 欧美日韩精品综合在线| 亚洲欧洲三级电影| 亚洲美女av电影| 欧美精品成人| 99av国产精品欲麻豆| 正在播放亚洲| 国产精品扒开腿爽爽爽视频| 99re66热这里只有精品4| 亚洲精品一区二区在线| 欧美好骚综合网| 日韩一级精品视频在线观看| 一本久道久久综合婷婷鲸鱼| 欧美三级特黄| 中国日韩欧美久久久久久久久| 亚洲一区二区免费看| 国产精品久久久久久久久久ktv| 亚洲午夜视频在线观看| 欧美一区二区日韩一区二区| 国产欧美视频一区二区| 久久精品人人做人人爽电影蜜月| 老司机免费视频一区二区三区| 亚洲电影免费观看高清完整版在线观看| 久久精品一本| 91久久久久久久久久久久久| 国产精品99久久久久久白浆小说| 国产精品高清在线| 久久久国产精品一区二区中文| 欧美成人三级在线| 一本一本a久久| 国产色产综合产在线视频| 久久深夜福利免费观看| 亚洲日本免费电影| 久久不射中文字幕| 亚洲激情社区| 国产精品国产三级国产aⅴ浪潮 | 免费亚洲一区二区| 日韩一区二区电影网| 久久久久综合网| 国产精品99久久久久久久久| 国产一区91| 欧美日韩免费观看一区三区| 欧美在线黄色| 日韩一级大片在线| 美女图片一区二区| 亚洲影院免费观看| 亚洲高清久久网| 国产精品乱码人人做人人爱| 老司机一区二区| 午夜精品在线| 一本色道久久综合狠狠躁篇的优点| 久久久久久精| 亚洲尤物在线视频观看| 亚洲国产欧美日韩精品| 国产精品综合久久久| 欧美大片在线看| 久久久高清一区二区三区| 亚洲视频一区在线| 亚洲日本中文| 欧美成人免费播放| 久久精品亚洲精品| 午夜国产欧美理论在线播放| 亚洲美洲欧洲综合国产一区| 狠狠操狠狠色综合网| 国产精品热久久久久夜色精品三区 | 亚洲精品免费观看| 欧美成人午夜视频| 久久免费视频在线| 午夜欧美大尺度福利影院在线看| 日韩视频免费大全中文字幕| 在线播放国产一区中文字幕剧情欧美 | 亚洲私人影吧| 日韩视频一区二区在线观看| 亚洲电影在线| 亚洲国产天堂久久综合网| 免费看av成人| 欧美a一区二区| 久久一区精品| 裸体歌舞表演一区二区| 久久美女艺术照精彩视频福利播放| 午夜宅男欧美| 欧美在线视频观看免费网站| 亚洲欧美久久久久一区二区三区| 一区二区毛片| 中文日韩电影网站| 亚洲一二三级电影| 亚洲一区二区在线免费观看视频| 中文精品在线| 亚洲欧美福利一区二区| 亚洲一区二区三区四区在线观看 | 国产三级精品三级| 国产一区二区按摩在线观看| 国内激情久久| 亚洲福利视频三区| av成人福利| 性高湖久久久久久久久| 欧美一区二区在线免费播放| 久久久久久香蕉网| 免费看亚洲片| 亚洲日本va午夜在线电影| 99pao成人国产永久免费视频| 宅男精品导航| 欧美在线看片| 欧美成人免费视频| 国产精品久久九九| 黑人中文字幕一区二区三区| 亚洲日韩中文字幕在线播放| 亚洲视频成人| 久久久久国产一区二区三区| 欧美岛国在线观看| 一本色道久久88综合日韩精品| 亚洲欧美区自拍先锋| 久久人人97超碰精品888| 欧美久久久久久| 国产欧美日韩在线视频| 最近中文字幕日韩精品| 亚洲一区二区三区四区在线观看| 久久久精品五月天| 亚洲日本成人在线观看| 欧美一区二区免费| 欧美精品尤物在线| 国产亚洲毛片在线| 99综合精品| 蜜臀av性久久久久蜜臀aⅴ| 日韩午夜激情| 久久夜色精品一区| 国产精品亚洲综合久久| 91久久中文| 久久亚洲精品中文字幕冲田杏梨 | 欧美激情一二三区| 亚洲欧美另类在线观看| 欧美国产日韩免费| 韩国三级电影久久久久久| 一区二区三区精品久久久| 蜜臀a∨国产成人精品| 亚洲综合不卡| 欧美日本三区| 亚洲黄色在线| 久久久亚洲精品一区二区三区| 一二三区精品福利视频| 免费观看日韩| 在线观看不卡| 久久久久久久国产| 亚洲欧美一区二区激情| 欧美四级剧情无删版影片|