叶酸每天什么时候吃最好| 依从性是什么意思| 藏青色t恤配什么颜色裤子| 刚产下的蚕卵是什么颜色| 糜烂性胃炎吃什么药好| 二建什么时候考试| 友五行属什么| 强直性脊柱炎有什么症状| 牙痛上火吃什么药| 代谢是什么| 什么是越位| 电是什么时候发明的| sayno是什么意思| 蛋白粉什么时候喝效果最好| 啄木鸟为什么不会脑震荡| 小狗能吃什么| 黑蝴蝶代表什么| 拿什么东西不用手| 矢的意思是什么| 脾气是什么意思| 台湾什么时候收回| 磨牙齿是什么原因| 老年痴呆吃什么药| 孕激素是什么意思| 吃什么水果养胃| 什么是平年| 小麦是什么| 胃立康片适合什么病| 獐子是什么动物| 美人鱼2什么时候上映| 伏羲是什么意思| 什么是哺乳动物| 腿抽筋挂什么科| 小孩腹泻吃什么药好得快| 女人阳虚吃什么药效果最好| 两极分化是什么意思| 肝郁血瘀吃什么中成药| 稽是什么意思| 无厘头是什么意思| 幽门螺杆菌抗体阳性什么意思| 为什么夏天容易拉肚子| 睡觉中途总醒什么原因| 故步自封是什么意思| 朱元璋是什么生肖| 咳嗽喝什么| 叶黄素对眼睛有什么功效| 胃不好吃什么好消化又有营养| 身上湿气重吃什么药| 身主天相是什么意思| 琥珀色是什么颜色| 为什么会得脑梗| 崎字五行属什么| 为什么胸会痒| 束缚的意思是什么| 做梦被打了是什么意思| 榴莲壳有什么用| 鼻塞一直不好什么原因| 下雨了是什么意思| 明胶是什么| 州字五行属什么| 10月20是什么星座| 汤沐邑是什么意思| 胃炎伴糜烂吃什么药效果好| 芊芊学子什么意思| 胆固醇高不可以吃什么| 为什么会有癌症| c4是什么驾驶证| 9月28号是什么星座| 叩齿是什么意思| 舌苔白厚吃什么药见效快| 什么驱蚊效果最好| 什么叫扁平疣长什么样| 晚上睡觉经常醒是什么原因| 山竹树长什么样| 补蛋白吃什么最好| 梦见很多苍蝇是什么意思| 平均血红蛋白浓度偏低是什么意思| 做肠镜前一天可以吃什么| 13朵玫瑰代表什么意思| 未见卵黄囊是什么意思| pt950是什么意思| 小儿支气管炎咳嗽吃什么药好得快| 无精是什么原因造成的| 儿童节送老婆什么礼物| 女性婚检都检查什么| 开宠物医院需要什么条件| 梦见吃水饺是什么预兆| 杨梅有什么好处| 总胆红素是什么意思| 什么是混合痔| 肝最怕什么| 护理学是干什么的| 为什么睡不着| 间歇性跛行见于什么病| 胃疼喝什么可以缓解| 眼袋大是什么原因| 葬爱家族是什么意思| 风凉话是什么意思| 逼上梁山什么意思| 牵牛花是什么颜色| 权志龙为什么这么火| 奥倍健是什么药| 什么药物过量会致死| 上海副市长什么级别| pm代表什么| 做穿刺是什么意思| 用盐袋子热敷小肚子有什么功效| 霉菌性阴道炎是什么引起的| 梭织棉是什么面料| 体温偏高的人说明什么| 基础代谢是什么| 转氨酶高有什么症状| 什么酷暑| 手指关节疼痛用什么药| 乙肝表面抗原阳性是什么意思| 横截面是什么意思| u是什么元素| 北是什么生肖| 尿频是什么原因| 淋巴是什么| 吃蜂蜜不能吃什么食物| 葡萄代表什么生肖| 聪明的动物是什么生肖| 绀是什么意思| 哈萨克斯坦是什么人种| 丈夫的弟弟叫什么| nbcs是什么意思| 头晕耳鸣是什么原因引起的| ushi是什么品牌男装| cartier什么牌子| fdi是什么意思| 海带补什么| 脚真菌感染用什么药最好| 青灰色是什么颜色| 胎动频繁到什么程度说明缺氧| 什么大河| 什么人不宜喝咖啡| 颈椎病是什么症状| 左室舒张功能减低什么意思| 什么仇什么怨| 私联是什么意思| 皮赘是什么| 做梦梦到自己怀孕了是什么意思| 清道夫鱼有什么作用| 教科书是什么意思| 考试前紧张吃什么药最好能缓解| 6月28日是什么星座| 千年等一回是什么生肖| 尿胆红素高是什么原因| 林是什么生肖| 什么什么鼎沸| 为难是什么意思| 香港商务签证需要什么条件| 前列腺ca是什么意思| 家里消毒杀菌用什么好| 左手食指麻木是什么原因引起的| 马克华菲属于什么档次| 吃芒果过敏吃什么药| 吃什么对心脏好改善供血不足| 蒽是什么意思| 酌情处理是什么意思| AR什么意思| 碱性土壤适合种植什么| 小便黄是什么原因引起的| 雪媚娘是什么| 正常的白带是什么样的| 婴儿什么时候会说话| 转氨酶高是什么原因造成的| 惊悉是什么意思| 端午节安康是什么意思| 白头发挂什么科| 什么动物有四个胃| 身陷囹圄是什么意思| 马拉车是什么牌子的包| 北京市副市长是什么级别| 酸辣粉是什么粉| rf医学上是什么意思| 支原体肺炎吃什么药| 跑步机cal是什么意思| 什么药治便秘效果最好最快| 牛黄清心丸适合什么人群吃| 伤口发炎吃什么消炎药| 雄脱是什么意思| 刘强东属什么生肖| ckd医学上是什么意思| 什么叫环比什么叫同比| 倒拔垂杨柳是什么意思| 万人迷是什么意思| 大暑是什么意思| 时刻是什么意思| 左耳发热是什么预兆| 发烧骨头疼是什么原因| 北京西单附近有什么好玩的| 坏血病的症状是什么| 花代表什么生肖| 皮肤感染吃什么消炎药| 癞皮狗是什么意思| 什么是命| 什么话什么说| 看望老人买什么礼物好| 吃维生素b2有什么好处和副作用| 一什么窗| evisu是什么牌子中文| 做爱吃什么药| 黑芝麻不能和什么一起吃| 前列腺液是什么颜色| 睡眠不好吃什么药最有效| 脑卒中是什么病| 索性是什么意思| 怀孕前3个月需要注意什么| 语文是什么意思| 缺维生素b有什么症状| 肺阳虚吃什么中成药| 12.24是什么星座| 12月11日什么星座| 12月23日是什么星座| 仙居杨梅什么时候上市| 纳是什么意思| ts什么意思网络上| 小孩子消化不好吃什么调理| 巨蟹和什么星座最配| 什么币最值钱| 什么的果实| 蟾酥是什么| 桃是什么生肖| 心率过快有什么危害| 吃什么可以让月经快点来| 扎心是什么意思| 小资情调是什么意思| 逆钟向转位是什么意思| 瘖什么意思| 57是什么意思| 晚上睡觉手麻是什么原因| 男生什么时候会有生理反应| 狮子座是什么象星座| 皮肤起水泡发痒是什么病| 一什么童话| 人为什么会生气| 手机NFC什么意思| 孕妇用什么驱蚊最安全| 县团级是什么级别| 吃什么去湿气最好最快| 破军星是什么意思| 破太岁是什么意思| 猫五行属什么| 膝盖内侧疼是什么原因| 鱼吃什么食物| 扶山是什么意思| normal什么意思| 结婚13年是什么婚| 冲锋衣是什么意思| 胃酸吃点什么药| 牛排和什么一起炖好吃| 旻读什么| 肚脐上面是什么部位| 牛仔布料是什么面料| 吃饭恶心想吐是什么原因| 心跳和心率有什么区别| 渐行渐远是什么意思| 为什么会头疼| 导是什么意思| 什么动物是爸爸生的| 牙膏属于什么类商品| 斑秃吃什么药| 百度Jump to content

手机厂商开启“全面屏”竞争 下半年逐渐量产

From Wikipedia, the free encyclopedia
百度 中信集团是经邓小平亲自倡导和批准、由前国家副主席荣毅...

In the programming language C++, unordered associative containers are a group of class templates in the C++ Standard Library that implement hash table variants. Being templates, they can be used to store arbitrary elements, such as integers or custom classes. The following containers are defined in the current revision of the C++ standard: unordered_set, unordered_map, unordered_multiset, unordered_multimap. Each of these containers differ only on constraints placed on their elements.

The unordered associative containers are similar to the associative containers in the C++ Standard Library but have different constraints. As their name implies, the elements in the unordered associative containers are not ordered. This is due to the use of hashing to store objects. The containers can still be iterated through like a regular associative container.

History

[edit]

The first widely used implementation of hash tables in the C++ language was hash_map, hash_set, hash_multimap, hash_multiset class templates of the Silicon Graphics (SGI) Standard Template Library (STL).[1] Due to their usefulness, they were later included in several other implementations of the C++ Standard Library (e.g., the GNU Compiler Collection's (GCC) libstdc++[2] and the Visual C++ (MSVC) standard library).

The hash_* class templates were proposed into C++ Technical Report 1 (C++ TR1) and were accepted under names unordered_*.[3] Later, they were incorporated into the C++11 revision of the C++ standard.[4] An implementation is also available in the Boost C++ Libraries as <boost/unordered_map.hpp>.[5]

Overview of functions

[edit]

The containers are defined in headers named after the names of the containers, e.g., unordered_set is defined in header <unordered_set>. All containers satisfy the requirements of the Container concept, which means they have begin(), end(), size(), max_size(), empty(), and swap() methods.

unordered_set
(C++11)
unordered_map
(C++11)
unordered_multiset
(C++11)
unordered_multimap
(C++11)
Description
(constructor) (constructor) (constructor) (constructor) Constructs the container from variety of sources
(destructor) (destructor) (destructor) (destructor) Destructs the set and the contained elements
operator= operator= operator= operator= Assigns values to the container
get_allocator get_allocator get_allocator get_allocator Returns the allocator used to allocate memory for the elements
Element access at Accesses specified element with bounds checking.
operator[] Accesses specified element without bounds checking.
Iterators begin begin begin begin Returns an iterator to the beginning of the container
end end end end Returns an iterator to the end of the container
Capacity empty empty empty empty Checks whether the container is empty
size size size size Returns number of elements in the container.
max_size max_size max_size max_size Returns the maximum possible number of elements in the container
Modifiers clear clear clear clear Clears the contents.
insert insert insert insert Inserts elements.
emplace emplace emplace emplace Constructs elements in-place (C++11)
emplace_hint emplace_hint emplace_hint emplace_hint Constructs elements in-place using a hint (C++11)
erase erase erase erase Erases elements.
swap swap swap swap Swaps the contents with another container.
Lookup count count count count Returns the number of elements matching specific key.
find find find find Finds an element with specific key.
equal_range equal_range equal_range equal_range Returns a range of elements matching specific key.
Bucket interface ...
Hash policy ...
Observers hash_function hash_function hash_function hash_function Returns the function used to create hash of a key
key_eq key_eq key_eq key_eq Returns key comparison function.

Usage example

[edit]
#include <iostream>
#include <string>
#include <unordered_map>
 
int main()
{
    std::unordered_map<std::string, int> months;
    months["january"] = 31;
    months["february"] = 28;
    months["march"] = 31;
    months["april"] = 30;
    months["may"] = 31;
    months["june"] = 30;
    months["july"] = 31;
    months["august"] = 31;
    months["september"] = 30;
    months["october"] = 31;
    months["november"] = 30;
    months["december"] = 31;
    std::cout << "september -> " << months["september"] << std::endl;
    std::cout << "april     -> " << months["april"] << std::endl;
    std::cout << "december  -> " << months["december"] << std::endl;
    std::cout << "february  -> " << months["february"] << std::endl;
    return 0;
}

Custom hash functions

[edit]

To use custom objects in std::unordered_map, a custom hash function must be defined. This function takes a const reference to the custom type and returns a size_t

#include <unordered_map>
 
struct X{int i,j,k;};

struct hash_X{
  size_t operator()(const X &x) const{
    return std::hash<int>()(x.i) ^ std::hash<int>()(x.j) ^ std::hash<int>()(x.k);
  }
};

The user defined function can be used as is in std::unordered_map, by passing it as a template parameter

 std::unordered_map<X,int,hash_X> my_map;

Or can be set as the default hash function by specializing the std::hash function

namespace std {
    template <>
        class hash<X>{
        public :
        size_t operator()(const X &x ) const{
            return hash<int>()(x.i) ^ hash<int>()(x.j) ^ hash<int>()(x.k);
        }
    };
}

//...
 std::unordered_map<X,int> my_map;

References

[edit]
  1. ^ "hash_map<Key, Data, HashFcn, EqualKey, Alloc>". Silicon Graphics (SGI). Retrieved 26 January 2011.
  2. ^ "libstdc++: hash_map Class Template Reference". Retrieved 26 January 2011.
  3. ^ WG21 (9 April 2003). "A Proposal to Add Hash Tables to the Standard Library (revision 4)". n1456.{{cite web}}: CS1 maint: numeric names: authors list (link)
  4. ^ WG21 (21 August 2010), Working Draft, Standard for Programming Language C++ (PDF), n3126{{citation}}: CS1 maint: numeric names: authors list (link)
  5. ^ "Class template unordered_map". Boost. Retrieved 26 January 2011.
什么东西解酒最好最快 吃什么能让子宫瘤变小 中性粒细胞高是什么感染 甘油三酯高吃什么食物 肚子疼吐了是什么原因
提手旁加茶念什么 反问是什么 淋巴细胞计数偏高是什么原因 阳历六月是什么星座 格列卫是什么药
体内湿气重是什么原因造成的 石斛有什么功效 39属什么生肖 肺部结节是什么意思啊 石膏的主要成分是什么
什么时候是情人节 孕妇贫血有什么症状 治飞蚊症用什么眼药水 有所作为的意思是什么 美女胸部长什么样
信子是什么意思hcv8jop2ns3r.cn 脂肪肝应注意什么hcv9jop7ns9r.cn 意念灰是什么意思hcv9jop1ns7r.cn 同性恋是什么意思hcv7jop7ns0r.cn 医者仁心是什么意思hcv8jop5ns8r.cn
1961年属什么hcv9jop7ns3r.cn 骨髓纤维化是什么病hcv9jop6ns0r.cn 1983属什么生肖hcv8jop5ns3r.cn 什么降血糖hcv8jop7ns5r.cn 妈妈的奶奶应该叫什么hcv7jop9ns4r.cn
经常想睡觉是什么原因gysmod.com 蒸鱼用什么鱼hcv9jop6ns6r.cn 氟苯尼考兽药治什么病hcv8jop6ns4r.cn 面瘫吃什么药好得快beikeqingting.com 减震器坏了有什么症状hcv7jop5ns4r.cn
eb病毒igg抗体阳性是什么意思sscsqa.com 梦见狼是什么意思周公解梦hcv8jop6ns0r.cn 为什么德牧不能打hcv9jop5ns8r.cn 织女是什么生肖hcv8jop3ns5r.cn 为什么会干呕hcv9jop1ns4r.cn
百度