STL(十五)hash_set哈希集合容器

        hash_set哈希集合容器是一种使用哈希表(hashtable)数据结构的具有高效数据检索的关联容器。作为一种集合容器,它的元素不论有多少个分量 ,都视为一个单一的数据类型,元素的键值就是元素本身。根据元素键值的大小,按照某个函数式子(哈希函数)直接计算元素的哈希地址,确定元素的具体存放位置。哈希函数是一个多对一的函数,不同元素可能具有相同的哈希地址。进行检索时,先计算元素的哈希地址,然后就可用较少的键值比较,将元素检索出来。

一、hash_set技术原理


二、hash_set应用基础

#include <hash_set>

1、创建hash_set对象

       hash_set()

       hash_set(size_type n)

       hash_set(size_type n, const hasher &h)

       hash_set(size_type n, const hasher &h, const key_equal &k)

       hash_set(const hash_set &)

2、元素的插入

       pair<iterator, bool>  insert(const value_type  &v)

       void insert(InputIterator  first, InputIterator  last)

3、元素的删除

       void erase(iterator  position)

       size_type   erase(const  key_type &k)

       void  erase(iterator  first, iterator last)

       void  clear()

4、元素的遍历访问

       iterator   begin()

       iterator   end()

5、元素的搜索

       iterator   find(const  key_type  &k)  const

6、其他的常用函数

       bool  empty() const

       size_type  size()  const

       size_type  bucket_count()  const

#include <iostream>
#include <hash_set>
int main(void) {
    using namespace std;
    hash_set<int>   hs;
    hs.insert(10);
    hs.insert(20);
    hs.insert(80);
    hs.insert(90);
    hs.insert(100);
    //
    cout << hs.empty() << endl;
    cout << hs.size()  << endl;
    cout << hs.bucket_count() << endl;
    return 0;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值