【C++】开散列实现unordered_map与unordered_set的封装

news2024/9/29 3:25:49

本文主要介绍unordered_map与unordered_set的封装,此次封装主要用上文所说到的开散列,通过开散列的一些改造来实现unordered_map与unordered_set的封装

文章目录

    • 一、模板参数
    • 二、string的特化
    • 三、正向迭代器
    • 四、构造与析构
    • 五、[]的实现
    • 六、unordered_map的实现
    • 七、unordered_set的实现
    • 八、哈希表代码

一、模板参数

由于unordered_set 是 K 模型的容器,而 unordered_map 是 KV 模型的容器,所以需要对结点的参数进行改造,unordered_set可以使用,unordered_map也可以使用,改为T _data即可

	template<class T>
	struct HashNode
	{
		T _data;
		HashNode<T>* _next;
		HashNode(const T& data)
			:_data(data)
			, _next(nullptr)
		{}
	};

T模板参数可能是键值Key,也可能是Key和Value构成的键值对。如果是unordered_map容器,那么它传入底层哈希表的模板参数就是Key和Key和Value构成的键值对,如果是unordered_set容器,那么它传入底层哈希表的模板参数就是Key和Key

	template<class K,class V,class Hash=HashFunc<K>>
	class unordered_map
	{
	private:
		buckethash::HashTable<K, pair<const K, V>, Hash, MapKeyOfT> _ht;
	};
	template<class K,class Hash = HashFunc<K>>
	class unordered_set
	{
     private: 
		buckethash::HashTable<K, K, Hash, SetKeyOfT> _ht;
	};

如此就可以实现泛型了,如果是unordered_set,结点当中存储的是键值Key;如果是unordered_map,结点当中存储的就是<Key, Value>键值对:

image-20230301073400540

哈希表仿函数的支持:KeyOfT👇

我们通过哈希计算出对应的哈希地址:但是插入的时候就不能直接用data去进行比较了

对于unordered_set:data是key是可以比较的,对于unordered_map:data是键值对,我们需要取出键值对的first。而data既可以是unordered_set的,也可以是unordered_map的,所以我们需要仿函数来实现不同容器所对应的需求,然后传入:

unordered_map返回kv.first

template<class K,class V,class Hash=HashFunc<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<const K, V>& kv)
			{
				return kv.first;
			}
		};
    }
	private:
		buckethash::HashTable<K, pair<const K, V>, Hash, MapKeyOfT> _ht;
	};

unordered_set返回key:

template<class K,class Hash = HashFunc<K>>
	class unordered_set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
     private: 
		buckethash::HashTable<K, K, Hash, SetKeyOfT> _ht;
	};

这也就是Hashtable需要KeyOfT的原因所在。

二、string的特化

字符串无法取模,在这里重新写一遍,字符串无法取模的问题写库的大神们早就想到了

image-20230301074411165

预留一个模板参数,无论上层容器是unordered_set还是unordered_map,我们都能够通过上层容器提供的仿函数获取到元素的键值

template<class K>
struct HashFunc
{
	size_t operator()(const K& key)
	{
		return (size_t)key;
	}
};
//特化
template<>
struct HashFunc<string>
{
	size_t operator()(const string& key)
	{
		size_t hash = 0;
		for (auto ch : key)
		{
			hash *= 131;
			//顺序?abc,cba
			hash += ch;
		}
		return hash;
	}
};

string的特化:符合string类型的优先走string类型

template<class K,class V,class Hash=HashFunc<K>>
class unordered_map
template<class K,class Hash = HashFunc<K>>
class unordered_set

三、正向迭代器

哈希表的正向迭代器对哈希表指针和结点指针进行了封装,++运算符重载,可以访问下一个非空的桶,所以每个正向迭代器里面存的是哈希表地址。

template<class K, class T, class Hash, class KeyOfT>
class HashTable;

	template<class K,class T,class Hash,class KeyOfT>
	struct __HTIterator
	{
		typedef HashNode<T> Node;
		typedef __HTIterator<K, T, Hash, KeyOfT> Self;
		typedef HashTable<K, T, Hash, KeyOfT> HT;

		Node* _node;
		HT* _ht;
    }

所以我们构造迭代器的时候需要知道节点的地址和哈希表的地址

	__HTIterator(Node*node,HT*ht)
			:_node(node)
			,_ht(ht)
		{}

++运算符重载的实现:如果当前的桶还有节点,那么++就是当前桶下一个节点,如果当前元素是所在的桶的最后一个元素,那么++就是下一个非空的桶了

image-20230301080113773

如何去找下一个非空桶:其实很简单,通过当前节点的值算出当前桶的hashi,然后++hashi就是下一个桶了,找到下一个非空桶即可

		T& operator*()
		{
			return _node->_data;
		}
		T* operator->()
		{
			return &_node->_data;
		}

		bool operator !=(const Self& s) const
		{
			return _node != s._node;
		}
		Self& operator++()
		{
			if (_node->_next)//当前桶还有节点
			{
				_node = _node->_next;
			}
            //找下一个非空的桶
			else
			{
				KeyOfT kot;
				Hash hash;
				size_t hashi = hash(kot(_node->_data)) % _ht->_tables.size();//当前桶的哈希地址
				++hashi;
				while (hashi < _ht->_tables.size())
				{
					if (_ht->_tables[hashi])//非空桶

					{
						_node = _ht->_tables[hashi];
						break;
					}
					else
					{
						++hashi;
					}
				}
				if (hashi == _ht->_tables.size())
				{
					_node = nullptr;
				}
			}
			return *this;
		}
	};

–问题:哈希表中的迭代器是单向迭代器,并没有反向迭代器,所以没有实现–-运算符的重载,若是想让哈希表支持双向遍历,可以考虑将哈希桶中存储的单链表结构换为双链表结构。

存在的小细节:👇

	template<class K,class T,class Hash,class KeyOfT>
	class HashTable
	{
		typedef HashNode<T> Node;
		template<class K,class T,class Hash,class KeyOfT>
		friend struct __HTIterator;

	public:
		typedef __HTIterator<K, T, Hash, KeyOfT> iterator;
		iterator begin()
		{
			for (size_t i = 0; i < _tables.size(); i++)
			{
				if (_tables[i])
				{
					return iterator(_tables[i], this);
				}
			}
			return iterator(nullptr, this);
		}
		iterator end()
		{
			return iterator(nullptr, this);
		}
      private:
		vector<Node*> _tables;
		size_t _n = 0;
    };

++运算符重载去寻找下一个结点时,会访问_tables,而_tables是哈希表中的私有成员,所以我们需要把迭代器__HTIterator声明为哈希表的友元

正向迭代器__HTIterator的typedef放在了public,这是为了外部能够使用我们的typedef之后的正向迭代器

还需要注意的是,哈希表的 const 迭代器不能复用普通迭代器的代码,我们查看源码:

image-20230301210902049

这与我们之前所复用的不同,上面stl源码中可以看到并没有用以前的复用:

这是因为如果使用const版本,那么_tables使用[]返回的就是const版本,那么Node*就相当于是const Node*,就会导致权限放大,无法构造;如果改成const HT* _ht; const Node* _node;,又会导致[]不能修改的问题:

image-20230301212422965

四、构造与析构

默认构造

HashTable()
			:_n(0)
		{
			_tables.resize(__stl_next_prime(0));
		}

析构函数

哈希表当中存储的结点都是new出来的,所以哈希表被析构时必须delete。在析构哈希表时我们只需要遍历取出非空的哈希桶,遍历哈希桶当中的结点并进行释放即可👇

		~HashTable()
		{
			for (size_t i = 0; i < _tables.size(); ++i)
			{
				// 释放桶
				Node* cur = _tables[i];
				while (cur)
				{
					Node* next = cur->_next;
					delete cur;
					cur = next;
				}

				_tables[i] = nullptr;
			}
		}

五、[]的实现

要想实现[],我们需要先把Insert的返回值修改成pair<iterator,bool>,最后的返回值也要一起修改

如果有重复的元素就返回这个找到it迭代器
没有重复的就返回newnode迭代器

		pair<iterator, bool> Insert(const T&data)
		{
			KeyOfT kot;
			iterator it = Find(kot(data));
			if (it != end())
			{
				return make_pair(it, false);
			}
			if (_tables.size() == _n)
			{
				vector<Node*> newTables;
				newTables.resize(__stl_next_prime(_tables.size()), nullptr);
				for (size_t i = 0; i < _tables.size(); i++)
				{
					Node* cur = _tables[i];
					while (cur)
					{
						Node* next = cur->_next;
						size_t hashi = Hash()(kot(cur->_data))% newTables.size();
						cur->_next = newTables[hashi];
						newTables[hashi] = cur;
						cur = next;
					}
					_tables[i] = nullptr;
				}
				_tables.swap(newTables);
			}
			size_t hashi = Hash()(kot(data)) % _tables.size();
			Node* newnode = new Node(data);
			newnode->_next = _tables[hashi];
			_tables[hashi] = newnode;
			++_n;
			return make_pair(iterator(newnode,this),true);
		}

六、unordered_map的实现

#pragma once

#include "HashTable.h"
namespace hwc
{
	template<class K,class V,class Hash=HashFunc<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<const K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename buckethash::HashTable<K, pair<const K, V>, Hash, MapKeyOfT>::iterator iterator;
		iterator begin()
		{
			return _ht.begin();
		}
		iterator end()
		{
			return _ht.end();
		}

		pair<iterator, bool> insert(const pair<K, V> data)
		{
			return _ht.Insert(data);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _ht.Insert(make_pair(key, V()));
			return ret.first->second;
		}
	private:
		buckethash::HashTable<K, pair<const K, V>, Hash, MapKeyOfT> _ht;
	};


	void test_unordered_map()
	{
		string arr[] = { "苹果","香蕉","苹果","西瓜","哈密瓜"};
		unordered_map<string, int> countMap;
		for (auto& e : arr)
		{
			countMap[e]++;
		}

		for (const auto& kv : countMap)
		{
			cout << kv.first << ":" << kv.second << endl;
		}
	}
}

七、unordered_set的实现

#pragma once

#include "HashTable.h"

namespace hwc
{
	template<class K,class Hash = HashFunc<K>>
	class unordered_set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename buckethash::HashTable<K, K, Hash, SetKeyOfT>::iterator iterator;
		iterator begin()
		{
			return _ht.begin();
		}
		iterator end()
		{
			return _ht.end();
		}
		pair<iterator, bool> insert(const K& key)
		{
			return _ht.Insert(key);
		}
	private: 
		buckethash::HashTable<K, K, Hash, SetKeyOfT> _ht;
	};


	void test_unordered_set()
	{
		unordered_set<int> us;
		us.insert(13);
		us.insert(3);
		us.insert(23);
		us.insert(5);
		us.insert(5);
		us.insert(6);
		us.insert(15);
		us.insert(223342);
		us.insert(22);

		unordered_set<int>::iterator it = us.begin();
		while (it != us.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : us)
		{
			cout << e << " ";
		}
		cout << endl;
	}
}

八、哈希表代码

#pragma once
#pragma once

#include <iostream>
#include <string>
#include <vector>
using namespace std;
template<class K>
struct HashFunc
{
	size_t operator()(const K& key)
	{
		return (size_t)key;
	}
};
//特化
template<>
struct HashFunc<string>
{
	size_t operator()(const string& key)
	{
		size_t hash = 0;
		for (auto ch : key)
		{
			hash *= 131;
			//顺序?abc,cba
			hash += ch;
		}
		return hash;
	}
};


//开散列
namespace buckethash
{
	template<class T>
	struct HashNode
	{
		T _data;
		HashNode<T>* _next;
		HashNode(const T& data)
			:_data(data)
			, _next(nullptr)
		{}
	};

	template<class K, class T, class Hash, class KeyOfT>
	class HashTable;

	template<class K,class T,class Hash,class KeyOfT>
	struct __HTIterator
	{
		typedef HashNode<T> Node;
		typedef __HTIterator<K, T, Hash, KeyOfT> Self;
		typedef HashTable<K, T, Hash, KeyOfT> HT;

		Node* _node;
		HT* _ht;

		__HTIterator(Node*node,HT*ht)
			:_node(node)
			,_ht(ht)
		{}

		T& operator*()
		{
			return _node->_data;
		}
		T* operator->()
		{
			return &_node->_data;
		}

		bool operator !=(const Self& s) const
		{
			return _node != s._node;
		}
		Self& operator++()
		{
			if (_node->_next)
			{
				_node = _node->_next;
			}
			else
			{
				KeyOfT kot;
				Hash hash;
				size_t hashi = hash(kot(_node->_data)) % _ht->_tables.size();
				++hashi;
				while (hashi < _ht->_tables.size())
				{
					if (_ht->_tables[hashi])
					{
						_node = _ht->_tables[hashi];
						break;
					}
					else
					{
						++hashi;
					}
				}
				if (hashi == _ht->_tables.size())
				{
					_node = nullptr;
				}
			}
			return *this;
		}
	};

	template<class K,class T,class Hash,class KeyOfT>
	class HashTable
	{
		typedef HashNode<T> Node;
		template<class K,class T,class Hash,class KeyOfT>
		friend struct __HTIterator;

	public:
		typedef __HTIterator<K, T, Hash, KeyOfT> iterator;
		iterator begin()
		{
			for (size_t i = 0; i < _tables.size(); i++)
			{
				if (_tables[i])
				{
					return iterator(_tables[i], this);
				}
			}
			return iterator(nullptr, this);
		}
		iterator end()
		{
			return iterator(nullptr, this);
		}



		HashTable()
			:_n(0)
		{
			_tables.resize(__stl_next_prime(0));
		}

		~HashTable()
		{
			for (size_t i = 0; i < _tables.size(); ++i)
			{
				// 释放桶
				Node* cur = _tables[i];
				while (cur)
				{
					Node* next = cur->_next;
					delete cur;
					cur = next;
				}

				_tables[i] = nullptr;
			}
		}

		pair<iterator, bool> Insert(const T&data)
		{
			KeyOfT kot;
			iterator it = Find(kot(data));
			if (it != end())
			{
				return make_pair(it, false);
			}
			if (_tables.size() == _n)
			{
				vector<Node*> newTables;
				newTables.resize(__stl_next_prime(_tables.size()), nullptr);
				for (size_t i = 0; i < _tables.size(); i++)
				{
					Node* cur = _tables[i];
					while (cur)
					{
						Node* next = cur->_next;
						size_t hashi = Hash()(kot(cur->_data))% newTables.size();
						cur->_next = newTables[hashi];
						newTables[hashi] = cur;
						cur = next;
					}
					_tables[i] = nullptr;
				}
				_tables.swap(newTables);
			}

			size_t hashi = Hash()(kot(data)) % _tables.size();
			Node* newnode = new Node(data);
			newnode->_next = _tables[hashi];
			_tables[hashi] = newnode;
			++_n;
			return make_pair(iterator(newnode,this),true);
		}

		iterator Find(const K& key)
		{
			KeyOfT kot;
			size_t hashi = Hash()(key) % _tables.size();
			Node* cur = _tables[hashi];
			while (cur)
			{
				if (kot(cur->_data) == key)
				{
					return iterator(cur, this);
				}
				else
				{
					cur = cur->_next;
				}
			}
			return end();
		}

		bool Erase(const K& key)
		{
			size_t hashi = Hash()(key) % _tables.size();
			Node* prev = nullptr;
			Node* cur = _tables[hashi];
			while (cur)
			{
				if (cur->_kv.first == key)
				{
					if (cur == _tables[hashi])
					{
						_tables[hashi] = cur->_next;
					}
					else
					{
						prev->_next = cur->_next;
					}
					delete cur;
					--_n;
					return true;
				}
				else
				{
					prev = cur;
					cur = cur->_next;
				}
			}
			return false;
		}
		inline unsigned long __stl_next_prime(unsigned long n)
		{
			static const int __stl_num_primes = 28;
			static const unsigned long __stl_prime_list[__stl_num_primes] =
			{
				53, 97, 193, 389, 769,
				1543, 3079, 6151, 12289, 24593,
				49157, 98317, 196613, 393241, 786433,
				1572869, 3145739, 6291469, 12582917, 25165843,
				50331653, 100663319, 201326611, 402653189, 805306457,
				1610612741, 3221225473, 4294967291
			};

			for (int i = 0; i < __stl_num_primes; ++i)
			{
				if (__stl_prime_list[i] > n)
				{
					return __stl_prime_list[i];
				}
			}

			return __stl_prime_list[__stl_num_primes - 1];
		}

	private:
		vector<Node*> _tables;
		size_t _n = 0;
	};
}

本篇到此结束…

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/381450.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MySQL安装教程

目录 一、认识MySQL 二、为什么要选用MySQL 三、关于MySQL8.0 四、安装步骤 一、认识MySQL 1、MySQL是一个开放源码的关系型数据库管理系统&#xff0c;将数据保存再不同的表中&#xff0c;而不是将所有数据放在一个大仓库内&#xff0c;这样就增加了速度并提高了灵活性。 …

【java基础】接口(interface)

文章目录基础介绍接口的定义关于接口字段和方法的说明使用接口抽象类和接口接口方法冲突的一些说明方法相同名称和参数&#xff0c;返回值相同方法名称相同&#xff0c;参数不同&#xff0c;返回值相同方法返回值不同&#xff0c;名称参数相同方法完全相同&#xff0c;一个有默…

中文预训练大模型—文心Ernie技术原理

文心Ernie技术原理 一、背景技术 Ernie是基于Bert模型进行改进&#xff0c;基本模型是Transformer&#xff0c;Bert完成的预训练任务是&#xff1a;完形填空&#xff08;通过基本语言单元掩码&#xff09;&#xff1b;上下句预测。 Bert模型的缺陷是&#xff1a;只能捕获局部…

关于Charles抓包

目录 抓包的原理 抓包的步骤 1. 下载Charles 2. PC抓HTTPS协议的包 3. 移动端抓包步骤 证书的原理 抓包的原理 抓包的软件非常多&#xff0c;其实底层逻辑充当了一个中间人代理的角色来对HTTPS进行抓包&#xff0c;结合日常自己用的Charles做一个记录。首先先了解抓包的原…

RT-Thread内核学习笔记

文章目录RT-Thread一、线程1. 线程定义2. 线程栈3. 线程函数 rt_thread_entry()4. 线程控制块 struct rt_thread5. 线程初始化 rt_thread_init()6. 就绪列表7. 调度器二、对象容器1. 对象&#xff1a;所有的数据结构都是对象2. 容器&#xff1a;每当创建一个对象&#xff0c;就…

腾讯云GPU游戏服务器/云主机租用配置价格表出炉!

用于游戏业务的服务器和普通云服务器和主机空间是不同的&#xff0c;游戏服务器对于硬件的配置、网络带宽有更大的要求&#xff0c;一般游戏服务器根据不同的配置和适用场景会有十几元一小时到几十元一小时&#xff0c;而且可以根据不同的按量计费。而普通的云服务器可能需要几…

【技术分享】配置802.1x 本地认证

实验需求 PC1(10.10.10.2/30)直接连接到RouterA的Eth2/0/1端口&#xff0c;RouterA的VLANIF10接口IP地址10.10.10.1/30&#xff08;为PC1上的网关IP地址&#xff09;&#xff0c;配置802.1x协议进行访问控制&#xff0c;认证方式采用本地认证。 实验步骤 RouterA的配置 V200R00…

Impala 在网易大数据的优化和实践

导读&#xff1a; 网易大数据平台的底层数据查询引擎&#xff0c;选用了 Impala 作为 OLAP 查询引擎&#xff0c;不但支撑了网易大数据的交互式查询与自助分析&#xff0c;还为外部客户提供了商业化的产品与服务。今天将为大家分享下 Impala 在网易大数据的优化和实践。 01 Im…

qnx的spi记录

https://www.cnblogs.com/schips/p/protocol_spi_about.html &#xff08;主要&#xff09;https://www.zhihu.com/question/308406342/answer/2901148391https://www.bbsmax.com/A/lk5aa4Pm51/ &#xff08;有基础测试代码&#xff09;https://baijiahao.baidu.com/s?id17460…

聚焦技术前沿 引领行业未来 | 第四届OpenI/O 启智开发者大会深度学习与大模型产业应用专场论坛顺利举办!

为探索人工智能的重要发展方向&#xff0c;深入了解大模型、深度学习领域&#xff0c;推动人工智能的快速发展&#xff0c;2月24日&#xff0c;第四届启智开发者大会以“引领前沿技术&#xff0c;推动产业升级”为主题的“深度学习与大模型产业应用专场”在深圳人才研修院智汇中…

数学知识(算法模板)

数学知识 文章目录数学知识一、质数一、试除法判定质数二、试除法分解质因数三、朴素筛法求素数四、线性筛法求素数二、约数一、试除法求所有约数二、约数个数约数之和三、欧几里得算法三、欧拉函数一、欧拉函数的定义二、筛法求欧拉函数四、快速幂一、快速幂二、快速幂求逆元扩…

Vue中rules表单验证,表单必填*显示位置不对,*显示位置错误

<el-form :model"ruleForm" :rules"rules" ref"ruleForm"><el-form-item label"名称" prop"name"><el-input v-model"ruleForm.name"></el-input></el-form-item> </el-form>…

.NET 使用NLog增强日志输出

引言 不管你是开发单体应用还是微服务应用&#xff0c;在实际的软件的开发、测试和运行阶段&#xff0c;开发者都需要借助日志来定位问题。因此一款好的日志组件将至关重要&#xff0c;在.NET 的开源生态中&#xff0c;目前主要有Serilog、Log4Net和NLog三款优秀的日志组件&…

少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(判断题)2022年12月

2022年12月scratch编程等级考试一级真题 判断题(共10题,每题2分,共20分) 26、可以通过四种方式添加新角色(不包括复制已有角色):选择一个角色、绘制、随机、上传角色 答案:对 考点分析:考查角色添加的方式,角色添加四种方式分别为题目给出的四种,所以正确 27、角…

分布式事务总结

1. 分布式事务产生的背景 1.1 数据库水平拆分 对于大部分的业务而言&#xff0c;在起步阶段&#xff0c;为了快速上线&#xff0c;一般都是单库单表的。但是随着业务的扩张&#xff0c;数据量也随着扩增&#xff0c;单库的性能逐渐变差&#xff0c;就会有数据库的单点压力。因…

大数据常见术语

大数据常见术语一览 主要内容包含以下&#xff08;收藏&#xff0c;转发给你身边的朋友&#xff09; 雪花模型、星型模型和星座模型 事实表 维度表 上钻与下钻 维度退化 数据湖 UV与PV 画像 ETL 机器学习 大数据杀熟 SKU与SPU 即席查询 数据湖 数据中台 ODS&#xff0c;DWD&…

过滤器的创建和执行顺序

过滤器的创建和执行顺序 8.1.1创建并配置过滤器 P143 重点是如何创建并配置&#xff08;xml&#xff09; 1.创建 public class EncodingFilter implements Filter {Overridepublic void init(FilterConfig filterConfig) throws ServletException {}Overridepublic void doFil…

Linux进程间通信:信号量(一)

前提知识 在介绍信号量之前&#xff0c;先来看看一些概念和一些简单的前提知识&#xff1a; 进程间通信的前提是让不同的进程看到同一份资源。于是&#xff0c;就有提出让这种资源成为一种公共资源的方法&#xff0c;方法的提出&#xff0c;导致了一种新的问题的出现&#xf…

MyBatis源码分析(二)SqlSessionFactory的构建及配置文件读取过程

文章目录一、MyBatis配置文件二、SqlSessionFactory的获取1、初始化XML配置的Document以及其他对象2、解析配置文件&#xff08;1&#xff09;配置Environment&#xff08;2&#xff09;存放Mapper&#xff08;3&#xff09;解析Mapper3、构造SqlSessionFactory4、总结未完待续…

测试2年,当初一起入行的朋友很多月薪20k了,自己却还没过万,到底差在了哪里?

说来奇怪&#xff0c;不管是读书还是工作&#xff0c;都存在一个现象&#xff0c;那就是人比人&#xff0c;比死人。读书的时候&#xff0c;不管是老师还是家长口中&#xff0c;总会有一个“别人家的孩子”。同样&#xff0c;到工作中&#xff0c;领导口中总会有一个“别人的员…