皮疹和湿疹有什么区别| 2型糖尿病是什么意思| 月德合是什么意思| 煽是什么意思| 狗狗拉虫子又细又长吃什么药| 摩纳哥为什么这么富| 吃什么会瘦| 产假从什么时候开始算| 相公是什么意思| 10月19日什么星座| 正常白带什么样| notice是什么意思| 玻尿酸是干什么用的| 国五行属什么| 夏天像什么| 11月2号什么星座| 蜘蛛结网预示着什么| 女人什么时候最想男人| 桃子不能跟什么一起吃| 鸡杂是什么| 为什么会干呕| 脸上长粉刺是什么原因| 男性生殖系统感染吃什么药| 繁花似锦什么意思| 淋巴细胞计数偏低是什么原因| 天天喝啤酒对身体有什么危害| 脚抽筋什么原因| 百依百顺是什么生肖| 上海新华医院擅长什么| 胸口闷闷的有点疼是什么原因| 霉菌感染用什么药好| 1965年属什么生肖| 年薪20万算什么水平| 儿童经常头晕什么原因导致的| 婴儿眉毛上黄痂是什么| 开心的反义词是什么| 辅食是什么意思| 口巴读什么| 51岁属什么生肖| 球拍状胎盘对胎儿有什么影响| 守字五行属什么| 跳蚤吃什么| 抽搐吃什么药| 后背有痣代表什么意思| 湿气重会有什么症状| 屌丝是什么| 罗红霉素和红霉素有什么区别| 疾苦的疾是什么意思| 肾炎是什么症状| 下一个台风什么时候来| 菠萝蜜吃多了有什么坏处| 郭富城什么星座| 消化不好吃什么药最好| 心理健康是什么| 查转氨酶挂什么科| 皮肤瘙痒用什么药好| 孕妇梦见西瓜是什么意思| 女人心肌缺血吃什么药| 为什么夏天容易掉头发| 乙肝抗体1000代表什么| 头晕是什么原因| 血小板高有什么危害| 将军是指什么生肖| 冰藤席是什么材质| 高圆圆老公叫什么名字| 皮肤过敏挂什么科| 容易水肿是什么原因| 低血压是什么| 热锅凉油是什么意思| 满人是什么民族| 孕妇适合喝什么牛奶| 血小板分布宽度偏高是什么意思| 什么叫suv车| 美育是什么| 满五唯一的房子要交什么税| 我想长胖点有什么办法| 加湿器用什么水比较好| 调理是什么意思| 颈椎病有什么症状| 尿液分析是检查什么| 问是什么结构| 生活老师是做什么的| 右手发麻是什么病的前兆| 偏头疼是什么症状| 飚是什么意思| 下联是什么| 健脾祛湿吃什么药| 微创手术是什么意思| 反清复明的组织叫什么| 养胃吃什么| 生气对身体有什么危害| 家财万贯是什么生肖| 尿素高是什么意思| 下嫁是什么意思| 夏天适合喝什么汤| 海带与什么食物相克| 做梦梦到狮子是什么意思| 晚上七点是什么时辰| 右大腿上部疼痛是什么原因| 什么叫211大学| 保健品是什么| 心衰吃什么药最好| 什么的教学楼| cordura是什么面料| 吃什么容易结石| 孩子咳嗽有痰吃什么药| 举头三尺有神明是什么意思| 膳食是什么| 生普洱和熟普洱有什么区别| 肺ca是什么意思| 雪里红是什么菜| 新房送什么礼物好| 一厢情愿是什么意思| 经常喝蜂蜜水有什么好处和坏处| 香港为什么不用人民币| 维生素b是什么食物| 肝火旺吃什么| 麦芒是什么意思| 猪狗不如是什么生肖| 唐筛是检查什么的| 刷酸是什么意思| 聪明绝顶是什么意思| lino是什么面料| 甲亢能吃什么水果| 青梅竹马什么意思| 吃什么解毒最快| 阑尾炎可以吃什么水果| 头疼喝什么饮料| 妯娌是什么意思| 碟鱼是什么鱼| 蛇最怕什么药| 利是什么生肖| none是什么意思| 头出汗多是什么原因| 皮肤痒用什么药最好| 碳14阴性是什么意思| 口苦吃什么中药| 溜号是什么意思| 咽拭子是检查什么的| 清明上河图描绘的是什么季节的景象| 子衿什么意思| 心肌病吃什么药| 肢体麻木是什么原因| 鱼油对眼睛有什么好处| 什么食物补气| 黄芪主治什么病| 印泥干了用什么稀释| 1930年属什么| 平均红细胞体积偏低是什么原因| 孝顺的真正含义是什么| 双排是什么意思| 热得直什么| 鸭锁骨是什么部位| 稼穑是什么意思| 1999属什么生肖| 两头尖是什么中药| 拉黑色大便是什么原因| 什么东西掉进水里不会湿| nsa是什么意思| 为什么不建议打卧蚕呢| 手抖头抖是什么病| 全身酸痛什么原因| 相手蟹吃什么| 补体c4偏低是什么意思| 干眼症什么症状| 甘甜的什么| 翡翠属于什么玉| 为什么会有同性恋| 喉咙有异物感吃什么药| 急性结膜炎用什么眼药水| 缓刑是什么意思还要坐牢吗| 后脑勺白头发多是什么原因| 宝宝胀气是什么原因引起的| spo2过低是什么意思| 丁克是什么| 红细胞计数偏低是什么意思| 花重锦官城的重是什么意思| 七九年属什么| 为什么会长智齿| 鹅肝为什么那么贵| 广西属于什么气候| 痦子和痣有什么区别| 今年三十属什么| 出国旅游需要什么手续和证件| 什么水果不能放冰箱| 十二指肠球炎是什么意思| 两个方一个土读什么| 便血鲜红色无疼痛是什么原因| 鸡吃什么长得又快又肥| 鑫字属于五行属什么| 早搏吃什么药最好| g点是什么| 肠子长息肉有什么症状| 急救物品五定是什么| 我要控制我自己是什么歌| 2002年什么年| 交链孢霉过敏是什么| 耳洞发炎用什么药| 湿疹是什么样子| 蚊子喜欢叮什么样的人| 1979属什么生肖| 6月23号是什么星座| 有福气是什么意思| abi是什么意思| 什么水果去火| 九转大肠是什么菜系| 颈动脉b超是检查什么| 利妥昔单抗是什么药| 什么病才查凝血四项呢| 黄金芽是什么茶| 禾五行属什么| 内痔用什么药| 补血最快的方法是什么| ghost是什么意思| 6月27是什么星座| 频繁打喷嚏是什么原因| 后背疼吃什么药| 水痘能吃什么| 2008年属鼠是什么命| 奥美拉唑是什么药| 小孩打喷嚏流鼻涕吃什么药| 30岁是什么之年| 新生儿吐奶是什么原因| 梦见床上有蛇什么预兆| 七月份怀孕预产期是什么时候| 医保卡是什么样子的图| 手指尖疼是什么原因| 睾丸疼痛吃什么药最好| 刮腻子是什么意思| 一个口一个我念什么| 2049年是什么年| 切糕为什么这么贵| 孔雀男是什么意思| ysl是什么意思| 梅毒rpr是什么| 吃羊肉不能吃什么水果| 螨虫是什么| 什么颜色加什么颜色等于蓝色| cp1是什么意思| 现在执行死刑用什么方法| 压测是什么意思| 疳积是什么| 锖色是什么颜色| 减肥餐吃什么| 夏季有什么水果| 蛋糕用什么奶油好| 电器发生火灾用什么灭火器| 省管干部是什么级别| 木耳菜是什么菜| 肠结核是什么病| 什么是太岁| 心率低有什么危害| yesido是什么意思| 猪猪侠叫什么| 百什么争鸣成语| 差强人意什么意思| 梦见相亲是什么意思| 肌酸是什么| 什么手组词| 大葱喜欢什么肥料| 什么东西嘴里没有舌头| 白细胞高吃什么药| 看睾丸去医院挂什么科| 腊月初七是什么星座| 百度Jump to content

商务部副部长亮开放“成绩单”回应中美贸易摩擦中美贸易摩擦

From Wikipedia, the free encyclopedia
(Redirected from Unordered set (C++))
百度 规范基层干部权力运行,加强对权力的约束,是防止滋生“蝇贪”的必要手段之一。

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.
王为念和王芳什么关系 喝酒伤什么 孕酮低吃什么补得快 打喷嚏是什么预兆 为什么全麻手术后不能睡觉
途字五行属什么 小心眼什么意思 君子兰不开花是什么原因 膝关节疼痛吃什么药好 hp是什么牌子的电脑
院士相当于什么级别 潘多拉是什么意思 头疼看什么科 小孩早上起床咳嗽是什么原因 什么地吃
肾虚用什么补最好 拔牙需要注意什么 小孩放屁很臭是什么原因 制氧机什么牌子好 为什么人一瘦就会漂亮
产假什么时候开始休xinjiangjialails.com 春天有什么花开hcv8jop8ns8r.cn 卤牛肉用什么部位hcv8jop5ns9r.cn 疑心病是什么意思jinxinzhichuang.com 小孩老是眨眼睛是什么原因hcv9jop3ns9r.cn
红斑狼疮复发的症状是什么hanqikai.com 乐不思蜀是什么意思hcv9jop7ns5r.cn 肩周炎是什么原因引起的hcv9jop4ns5r.cn 因特网是什么意思hcv9jop8ns0r.cn 女孩名字带什么字好听hcv8jop0ns6r.cn
金黄金黄的什么hcv7jop6ns6r.cn 早泄是什么原因hcv8jop0ns0r.cn 当局是什么意思hcv9jop2ns2r.cn 狗吃什么蔬菜好hcv9jop3ns8r.cn 什么鸣什么盗xinmaowt.com
什么西瓜好吃hcv8jop5ns2r.cn 梨状肌综合征吃什么药hcv9jop5ns4r.cn 做深蹲有什么好处hcv8jop2ns0r.cn 中东为什么叫中东kuyehao.com 植物纤维是什么面料hcv8jop8ns2r.cn
百度