当前位置: 首页 > news >正文

内蒙古地区做推广网站什么是网络营销战略

内蒙古地区做推广网站,什么是网络营销战略,嘉峪关建设局网站,pos机网站模板文章目录 一、unordered_set、unordered_map的介绍二、哈希表的建立方法2.1闭散列2.2开散列(哈希桶/拉链法) 三、闭散列代码(除留余数法)四、开散列代码(拉链法/哈希桶) 一、unordered_set、unordered_map的…

文章目录

    • 一、unordered_set、unordered_map的介绍
    • 二、哈希表的建立方法
      • 2.1闭散列
      • 2.2开散列(哈希桶/拉链法)
    • 三、闭散列代码(除留余数法)
    • 四、开散列代码(拉链法/哈希桶)

一、unordered_set、unordered_map的介绍

1.unordered_set、unordered_map的底层是哈希表,哈希表是一种关联式容器(与前面的二叉搜索树、AVL树、红黑树一样,数据与数据之间有很强的关联性)
2.单向迭代器(map、set是双向迭代器)
3.哈希表的查找顺序是O(1),性能比红黑树(logn)好一些(在数据接近与有序的情况下与哈希表一样)。

二、哈希表的建立方法

2.1闭散列

在这里插入图片描述
缺点:值很分散,直接定址会导致空间开很大,浪费。

2.2开散列(哈希桶/拉链法)

在这里插入图片描述
除留余数法会发生哈希碰撞(关键字可以很分散,量可以很大,关键字-存储位置是多对一的关系,存在哈希冲突):不同的值映射到相同的位置上去。
负载因子(存储数据的个数/表的大小,也就是空间的占用率):存储关键字的个数/空间大小

三、闭散列代码(除留余数法)

#pragma once
#include<iostream>
#include<vector>
#include<string>
using namespace std;template<class K>
struct HashFunc
{size_t operator()(const K& key){return key;}
};template<>
struct HashFunc<string>
{size_t operator()(const string& kv){size_t hashi = 0;for (auto e : kv){hashi *= 31;hashi += e;}return hashi;}
};namespace close
{enum Status{EMPTY,EXIST,DELETE};template<class K,class V>struct HashData{pair<K, V> _kv;Status _s;//表示状态};template<class K,class V,class Hash = HashFunc<K>>class HashTable{public:typedef HashData<K, V> data;HashTable(){_tables.resize(10);}data* find(const K key){size_t hash = key % _tables.size();while (_tables[hash]._s!=EMPTY){if (_tables[hash]._s == EXIST && _tables[hash]._kv.first == key)return &_tables[hash];hash++;hash %= _tables.size();}return nullptr;}bool insert(const pair<K,V>& kv){Hash hf;if (find(kv.first))return false;if (_n * 10 / _tables.size() == 7){//建新表HashTable<K,V,Hash> newtable;newtable._tables.resize(_tables.size() * 2);for (size_t i = 0; i < _tables.size(); i++){if (_tables[i]._s == EXIST)newtable.insert(_tables[i]._kv);}_tables.swap(newtable._tables);}size_t hash = hf(kv.first) % _tables.size();//线性探测while (_tables[hash]._s != EMPTY){hash++;hash %= _tables.size();}_tables[hash]._kv = kv;_tables[hash]._s = EXIST;_n++;return true;}bool erase(const K& key){data* ret = find(key);if (ret){_n--;ret->_s == DELETE;return true;}return false;}void Print(){for (size_t i = 0; i < _tables.size(); i++){if (_tables[i]._s == EXIST){//printf("[%d]->%d\n", i, _tables[i]._kv.first);cout << "[" << i << "]->" << _tables[i]._kv.first << ":" << _tables[i]._kv.second << endl;}else if (_tables[i]._s == EMPTY){printf("[%d]->\n", i);}else{printf("[%d]->D\n", i);}}cout << endl;}private:vector<data> _tables;size_t _n = 0;};}

四、开散列代码(拉链法/哈希桶)

namespace hash_bucket
{template<class K,class V>struct HashNode{pair<K, V> _kv;HashNode<K, V>* _next;};template<class K,class V,class Hash = HashFunc<K>>class HashTable{public:typedef HashNode<K, V> Node;HashTable(){_tables.resize(10, nullptr);}~HashTable(){for (size_t i = 0; i < _tables.size(); i++){Node* cur = _tables[i];if (cur){Node* next = cur->_next;delete cur;cur = next;}_tables[i] = nullptr;}}Node* find(const K& key){Hash hf;size_t hash = hf(key) % _tables.size();Node* cur = _tables[hash];while (cur){if (hf(cur->_kv.first) == hf(key))return cur;cur = cur->_next;}return nullptr;}bool insert(pair<K,V>& kv){Hash hf;if (find(kv.first))return false;if (_bucket == _tables.size()){HashTable newtable;newtable._tables.resize(_tables.size() * 2, nullptr);for (size_t i = 0; i < _tables.size(); i++){Node* cur = _tables[i];while (cur){size_t hash = hf(cur->_kv.first) % newtable._tables.size();cur->_next = newtable._tables[hash];newtable._tables[hash] = cur;cur = cur->_next;}}_tables.swap(newtable._tables);}size_t hash = hf(kv.first) % _tables.size();Node* cur = new Node(kv);cur->_next = _tables[hash];_tables[hash] = cur;_bucket++;return true;}bool erase(const K& key){Hash hf;size_t hash = hf(key) % _tables.size();Node* cur = _tables[hash];Node* prev = nullptr;while (cur){if (hf(key) == hf(_tables[hash]->_kv.first)){_tables[hash] = cur->_next;delete cur;return true;}else{if (hf(key) == hf(cur->_kv.first)){prev->_next = cur->_next;delete cur;return true;}prev = cur;cur = cur->_next;}}_bucket--;return false;}private:vector<Node*> _tables;size_t _bucket = 0;};}

代码解读:这里的插入节点是头插(效率高一些)

http://www.hkea.cn/news/606963/

相关文章:

  • 电商网站开发服务全网营销骗局揭秘
  • 个人网站怎么做互联网营销师培训课程免费
  • 微信网站建设价格网站开发报价方案
  • wordpress utc时间慢8小时大连seo关键词排名
  • 中国建设承包商网站创建软件平台该怎么做
  • 中小企业网站建设费用海外推广服务
  • 企业名称的英文做网站名seo是怎么优化推广的
  • 手机在线建站西安seo服务公司
  • 网站开发有前途吗我也要投放广告
  • 备案 网站名称怎么写crm软件
  • 扁平式网站模板b2b网站推广优化
  • 做外贸网站网络营销咨询服务
  • 江门网站建设方案报价淘宝seo优化怎么做
  • 盘龙城做网站推广网站推广
  • 如何做电子书网站域名站长工具
  • 物联网平台有哪些排名优化外包公司
  • 秦皇岛汽车网站制作数字营销工具
  • 培训教育的网站怎么做东莞做网站的联系电话
  • 云南做网站的公司外贸谷歌优化
  • 网页设计学徒培训可试学巢湖seo推广
  • 让顾客心动的句子seo模拟点击软件源码
  • 设计类专业包括哪些kj6699的seo综合查询
  • 手机网站制作哪家好查关键词
  • 米拓企业网站管理系统电商培训机构排名前十
  • 做效果图有哪些网站seo点击排名
  • 网络营销推广网站收录seo推广排名平台有哪些
  • 产品经理如何看待网站开发广州软件系统开发seo推广
  • wordpress 忘记管理员如何做网站seo
  • app和网站哪个有优势淘宝关键词排名
  • wordpress该域名宁波网站seo公司