久久久久久久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 轉換單一顏色)
主站蜘蛛池模板: 午夜男人天堂 | 精品一区二区三区日本 | 亚洲成av人片在线观看 | 中文字幕一区二区三区四区五区 | 久久久久久久久综合 | 欧美精品欧美精品系列 | 91毛片在线看 | 欧美日韩国产一区二区 | 国产亚洲第一页 | 欧美日韩不卡合集视频 | 搞黄网站在线观看 | 福利网站在线观看 | 精品国产成人 | 亚洲欧美在线观看 | 国产一区影院 | 亚洲在线 | 欧美精品网站 | 国产综合在线视频 | 亚洲国产精品第一区二区 | 国产日韩欧美精品一区二区 | 97视频在线免费 | 福利视频一区二区三区 | a视频在线 | 一区二区三区高清 | 日本精品一区二区三区在线观看 | 亚洲国产精品一区二区第一页 | 一级毛片在线播放 | 亚洲精品视频一区二区三区 | 欧美a在线 | 精品国产一区二区三区免费 | 男人av在线播放 | 欧美日韩一区精品 | 久久久精品一区二区三区 | 蜜桃视频在线观看免费视频网站www | 成人精品一区二区三区中文字幕 | 久久精品欧美一区二区三区麻豆 | av黄色在线观看 | 国产一区二区在线播放 | 成人区一区二区三区 | 欧美日韩久久 | 午夜影院中文字幕 |