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

网站公示如何做链接中太建设集团官方网站

网站公示如何做链接,中太建设集团官方网站,网站运营管理的内容有哪些,网站建设价格怎么算个人主页#xff1a;仍有未知等待探索-CSDN博客 专题分栏#xff1a;C 本文着重于模拟实现哈希表#xff0c;并非是哈希表的使用。 实现的哈希表的底层用的是线性探测法#xff0c;并非是哈希桶。 目录 一、标准库中的哈希表 1、unordered_map 2、unordered_set 二、模… 个人主页仍有未知等待探索-CSDN博客 专题分栏C 本文着重于模拟实现哈希表并非是哈希表的使用。 实现的哈希表的底层用的是线性探测法并非是哈希桶。 目录 一、标准库中的哈希表 1、unordered_map 2、unordered_set 二、模拟实现哈希表 1、结构 2、注解hashtable的模板参数 3、重难点 1、二元“!” 没有找到接收类型的右操作数的运算符​编辑 2、迭代器的本质、const和非const的区别 3、类A在类B的上面想要在类A中使用以类B为类型的变量怎么办 4、类A在类B的上面想要在类A中使用类B的私有成员怎么办 三、代码 一、标准库中的哈希表 这两个是两种不同映射关系的哈希表。 unordered_map是 Key - Value 的映射关系 也就是 关键字和键值 之间的映射 unordered_set是 Value 的映射关系也就是只有 键值 的映射 这两种不同的映射关系从各自的模板参数就能看出来。 1、unordered_map unordered_map又分为两种一种是unordered_map另一种是unordered_multimap。 这两种有什么区别呢 以unordered_map为例 这里面的模板参数 Key - T 就是这个容器存储的键值关系。 2、unordered_set 同样unordered_set又分为两种一种是unordered_set另一种是unordered_multiset。 这两个的区别和unordered_map中两个的区别一样。 二、模拟实现哈希表 1、结构 在模拟实现哈希表前我们要知道整个实现的结构要有完整性的认识。 这个就是哈希表的大致底层结构。 2、注解hashtable的模板参数 Key是上层结构也就是unordered_set、unordered_map的关键字。T是存的关键字和键值的映射。 也就是unordered_setpairKey, Keyunordered_map:pairKey, Vaule Ptr是T*。Ref是T。KeyofT是一个仿函数用来取T的Key。因为在这一层也不知道上一层是unordered_set、unordered_map所以还需要传一个仿函数来进行取值。hashfunc是一个仿函数用来计算hash映射值。 对于一个整数怎么存储到哈希表里需要对其进行hash计算将这个整数取模于表的大小得到。 对于一个字符串怎么存储到哈希表里需要对其进行hash计算将这个字符串转换成整数然后将这个整数取模于表的大小得到下标。 如果得到的下标冲突了就用哈希线性探测法解决冲突。 3、重难点 写完不算难难的是找bug。 1、二元“!” 没有找到接收类型的右操作数的运算符 类型不匹配你可以去你出错的位置看看该类型的模板参数的类型匹不匹配。 2、迭代器的本质、const和非const的区别 迭代器就是模拟的指针的行为。 const迭代器和非const迭代器的区别就是限制其*和-运算符的返回值。 3、类A在类B的上面想要在类A中使用以类B为类型的变量怎么办 在类A的前面加上类B的前置声明即可。 4、类A在类B的上面想要在类A中使用类B的私有成员怎么办 在类B中加上类A的友元。 三、代码 hash.h #pragma once#include iostream #include vector #include string using namespace std; enum State {Empty,Exist,Delete }; // hash_func --- 用来对任意类型进行编码 templateclass T struct hash_func {size_t operator()(const T _val){return (size_t)_val;} }; // 对string类型进行特化 template struct hash_funcstring {size_t operator()(const string val){size_t hash 0;for (auto e : val){hash * 131;hash e;}return hash;} };// 闭散列 --- 线性探测 // 这里的 T 是 K or pairK, V template class T struct HashNode {HashNode() {}HashNode(const HashNode) default;HashNode(const T data, const State state):_data(data),_state(state){}T _data;State _state Empty;};template class K, class V, class Ptr, class Ref, class KeyofT, class HashFunc class HashTable;templateclass K, class T, class Ptr, class Ref, class KeyofT struct HashTable_iterator {typedef HashNodeT HashNode;typedef HashTable_iteratorK, T, Ptr, Ref, KeyofT iterator;typedef HashTableK, T, Ptr, Ref, KeyofT, hash_funcK hashtable;HashNode* _node;hashtable* _pht;KeyofT kot;hash_funcK hs;HashTable_iterator(HashNode* node, hashtable* pht):_node(node), _pht(pht){}bool operator!(const iterator s){return _node ! s._node;}Ref operator*(){return _node-_data;}Ptr operator-(){return (_node-_data);}iterator operator(){int hashindex 0;for (int i 0; i _pht-_tables.size(); i){// 找到当前节点的位置寻找下一个节点的位置if (_pht-_tables[i] _node){hashindex i;break;}}for (int i hashindex 1; i _pht-_tables.size(); i){if (_pht-_tables[i] _pht-_tables[i]-_state Exist){_node _pht-_tables[i];return *this;}}_node nullptr;return *this;} };template class K, class V, class Ptr, class Ref, class KeyofT, class HashFunc hash_funcK class HashTable {typedef HashNodeV hashnode;typedef HashTableK, V, Ptr, Ref, KeyofT, hash_funcK hashtable;templateclass K, class T, class Ptr, class Ref, class KeyofTfriend struct HashTable_iterator;typedef HashTable_iteratorK, V, Ptr, Ref, KeyofT iterator;public:hash_funcK hf;KeyofT kot;HashTable(size_t n 10):_size(0){_tables.resize(n);}iterator begin(){for (int i 0; i _tables.size(); i){hashnode* cur _tables[i];if (cur cur-_state Exist){// this - HashTable*return iterator(cur, this);}}return end();}iterator end(){return iterator(nullptr, this);}// V : V or pairK, Vpairiterator, bool insert(const V e){iterator it find(kot(e));if (it ! end()){return make_pair(it, false);}if (_size * 10 / _tables.size() 7){hashtable newt(_tables.size() * 2);for (int i 0; i _tables.size(); i ){if (_tables[i]-_state Exist){newt.insert(_tables[i]-_data);}}_tables.swap(newt._tables);}size_t hashindex hf(kot(e)) % _tables.size();while (_tables[hashindex] _tables[hashindex]-_state Exist){hashindex;hashindex % _tables.size();}hashnode* newnode new hashnode(e, Exist);swap(_tables[hashindex], newnode);delete newnode;_size;return make_pair(iterator(_tables[hashindex], this), true);}iterator find(const K key){size_t hashindex hf(key)% _tables.size();while (_tables[hashindex] _tables[hashindex]-_state ! Empty){if (_tables[hashindex]-_state Exist kot(_tables[hashindex]-_data) key){return iterator(_tables[hashindex], this);}hashindex;hashindex % _tables.size();}return iterator(nullptr, this);}bool erase(const K key){iterator t find(key);if (t._node nullptr) return false;else{t._node-_state Delete;--_size;}return true;} private:vectorhashnode* _tables;size_t _size; };unordered_map.h #pragma once#include hash.htemplateclass K, class V class unordered_map {struct MapKeyofT{const K operator()(const pairconst K, V key){return key.first;}}; public:typedef HashTableK, pairconst K, V, pairconst K, V*, pairconst K, V, MapKeyofT, hash_funcK HashTable;typedef HashNodepairconst K, V HashNode;typedef HashTable_iteratorK, pairconst K, V, pairconst K, V*, pairconst K, V, MapKeyofT iterator;iterator begin(){return _ht.begin();}iterator end(){return _ht.end();}pairiterator, bool insert(const pairconst K, V kv){return _ht.insert(kv);}iterator find(const K key){return _ht.find(key);}bool erase(const K key){return _ht.erase(key);}V operator[](const K key){pairK, V pkv make_pair(key, V());pairiterator, bool ret insert(pkv);return ret.first-second;} private:HashTable _ht; };//void map01() //{ // unordered_mapint, int s1; // vectorint v { 1, 8, 34, 5, 3, 4, 8, 1111, 111, 11 }; // // for (auto e : v) // { // s1.insert({e, e}); // } // // s1.erase(1111); // s1.erase(8); //} // //void map02() //{ // unordered_mapstring, int s1; // vectorstring v { 1234, 233, a, b, 1234, 233, a, b }; // // for (auto e : v) // { // s1.insert({e, 1}); // } // // s1.erase(1234); // s1.erase(8); //} unordered_set.h #pragma once#include hash.htemplateclass K class unordered_set {struct SetKeyofT{const K operator()(const K key){return key;}}; public:typedef HashTableK, K, const K*, const K, SetKeyofT, hash_funcK HashTable;typedef HashNodeK HashNode;typedef HashTable_iteratorK, K, const K*, const K, SetKeyofT iterator;iterator begin(){return _ht.begin();}iterator end(){return _ht.end();}pairiterator, bool insert(const K val){return _ht.insert(val);}iterator find(const K key){return _ht.find(key);}bool erase(const K key){return _ht.erase(key);} private:HashTable _ht; };//void set01() //{ // unordered_setint s1; // vectorint v { 1, 8, 34, 5, 3, 4, 8, 1111, 11, 11}; // // for (auto e : v) // { // s1.insert(e); // } // // s1.erase(1111); //} //void set02() //{ // unordered_setstring s; // vectorstring v { 1234, 233, a, b }; // // for (auto e : v) // { // s.insert(e); // } // // s.erase(1111); // s.erase(1234); //} 谢谢大家
http://www.hkea.cn/news/14278236/

相关文章:

  • 二道网站建设制作网站的图片素材
  • 用手机做电影网站瑞幸咖啡网络营销策划方案
  • ps网页制作视频教程宁晋seo网站优化排名
  • 用自己的服务器做网站网站建站代理
  • 网站建设怎么说服客户营销型网站建设课程培训现场
  • 北京市建设工程信息网站认证网站源码
  • 网站怎样添加友情链接怎么搭建个人网站
  • 无锡网站制作楚天软件如何在外国网站卖东西
  • 电子科技大学网站开发制定合同长春财经学院是一本还是二本
  • 广州网站营销优化qq做logo去哪个网站
  • 网站推广模板网站的目录怎样做的
  • 建立企业网站惠州做网站的公司有哪些
  • 德州专业网站制作哪家好lda模型 文本建模 wordpress
  • 旅行社的网站建设网站建设就业怎么样
  • 沈阳手机网站wordpress天气
  • 性价比高的网站建设做3d动画视频接私活的网站
  • 杭州建设网 工程信息网站wordpress主题--ux
  • 国外设计网站d开头的可以发外链的网站整理
  • 重庆网站制作公司电话口碑营销5t理论
  • 易县做网站的在哪wordpress汉化插件库
  • 网站原创文章网站模板建站教程视频
  • 网站模板是怎么制作新余网站网站建设
  • 旅游网站平台建设方案策划书服饰网站建设模板
  • 网站关键词百度排名在下降wordpress 阅读统计
  • 做网站图片为什么不清晰12306网站建设
  • 从化做网站做网站架构需要什么工具
  • 做系统和做网站哪个简单一些android studio模拟器
  • 番禺网站建设公司有哪些网站的布局分类
  • iis网站建设网站建设新闻分享
  • 桥梁建设网站wordpress文章价格产品价格