久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

跟蹤插入順序的 std::map ?

A std::map that keep track of the order of insertion?(跟蹤插入順序的 std::map ?)
本文介紹了跟蹤插入順序的 std::map ?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前有一個 std::map 將一個整數值存儲到一個唯一的字符串標識符中,我確實使用該字符串進行查找.它主要做我想要的,除了它不跟蹤插入順序.因此,當我迭代地圖以打印出值時,它們會根據字符串進行排序;但我希望它們按照(第一次)插入的順序進行排序.

I currently have a std::map<std::string,int> that stores an integer value to a unique string identifier, and I do look up with the string. It does mostly what I want, except that it does not keep track of the insertion order. So when I iterate the map to print out the values, they are sorted according to the string; but I want them to be sorted according to the order of (first) insertion.

我想過使用 vector> 代替,但我需要查找字符串并將整數值增加大約 10,000,000 次,所以我不知道std::vector 是否會明顯變慢.

I thought about using a vector<pair<string,int>> instead, but I need to look up the string and increment the integer values about 10,000,000 times, so I don't know whether a std::vector will be significantly slower.

有沒有一種方法可以使用 std::map 或者是否有另一個更適合我需要的 std 容器?

Is there a way to use std::map or is there another std container that better suits my need?

我使用的是 GCC 3.4,我的 std::map 中的值可能不超過 50 對.

I'm on GCC 3.4, and I have probably no more than 50 pairs of values in my std::map.

推薦答案

如果 std::map 中只有 50 個值,您可以將它們復制到 std::vector> 在使用適當的函子通過 std::sort 打印和排序之前.

If you have only 50 values in std::map you could copy them to std::vector before printing out and sort via std::sort using appropriate functor.

或者你可以使用 boost::multi_index.它允許使用多個索引.在您的情況下,它可能如下所示:

Or you could use boost::multi_index. It allows to use several indexes. In your case it could look like the following:

struct value_t {
      string s;
      int    i;
};

struct string_tag {};

typedef multi_index_container<
    value_t,
    indexed_by<
        random_access<>, // this index represents insertion order
        hashed_unique< tag<string_tag>, member<value_t, string, &value_t::s> >
    >
> values_t;

這篇關于跟蹤插入順序的 std::map ?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 91av视频在线观看 | av网站在线免费观看 | 国产精品永久免费视频 | 亚洲444kkkk在线观看最新 | 国产成人精品一区二三区在线观看 | av黄色网| 男人天堂社区 | 综合网视频 | 国产不卡视频 | 日本一区视频在线观看 | 热99| 欧美一区二区三区的 | 国产一级特黄真人毛片 | 国产精品久久久久999 | 中文字幕免费 | 狠狠入ady亚洲精品经典电影 | www日本在线播放 | 日韩一区二区精品 | 成人欧美一区二区 | 日韩中文字幕视频 | 日韩一二区在线 | 亚洲 欧美 日韩在线 | 少妇淫片aaaaa毛片叫床爽 | 羞羞在线观看视频 | 视频一区二区三区在线观看 | 久久亚洲国产精品日日av夜夜 | 欧美日韩国产一区二区三区 | 国产午夜精品视频 | 国产精品一区二区av | 欧美日韩国产高清 | 日本精a在线观看 | 天堂素人约啪 | 在线一级片 | 亚洲视频免费在线看 | 91精品国产一二三 | 欧洲精品码一区二区三区免费看 | 天天操操 | 午夜三区 | 国产一二三视频在线观看 | 99欧美精品 | 99精品一区二区三区 |