C++之unordered_map,unordered_set模拟实现

news2024/9/23 17:23:21

unordered_map,unordered_set模拟实现

  • 哈希表源代码
  • 哈希表模板参数的控制
  • 仿函数增加
  • 正向迭代器实现
    • *运算符重载
    • ->运算符重载
    • ++运算符重载
    • != 和 == 运算符重载
    • begin()与end()实现
  • unordered_set实现
  • unordered_map实现
  • map/set 与 unordered_map/unordered_set对比
  • 哈希表调整后代码

哈希表源代码

template<class K>
struct HashFunc
{
	size_t operator()(const K& key)
	{
		//所有类型都强转为size_t类型
		return (size_t)key;
	}
};

//模板特化
template<>
struct HashFunc<string>
{
	size_t operator()(const string& key)
	{
		size_t val = 0;
		for (auto ch : key)
		{
			val *= 131;
			val += ch;
		}

		return val;
	}
};
namespace HashBucket
{
	template<class K, class V>
	struct HashNode
	{
		pair<K, V> _kv;
		HashNode<K, V>* _next;

		//构造函数
		HashNode(const pair<K, V>& kv)
			:_kv(kv)
			,_next(nullptr)
		{}
	};

	template<class K, class V, class Hash = HashFunc<K>>
	class HashTable
	{
		typedef HashNode<K, V> Node;
	public:

		~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;
			}
		}

		inline size_t __stl_next_prime(size_t n)
		{
			static const size_t __stl_num_primes = 28;
			static const size_t __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 (size_t i = 0; i < __stl_num_primes; ++i)
			{
				if (__stl_prime_list[i] > n)
				{
					return __stl_prime_list[i];
				}
			}

			return -1;
		}
		bool Insert(const pair<K, V>& kv)
		{
			//如果该键值对存在,就返回false
			if (Find(kv.first))
			{
				return false;
			}

			Hash hash;
			//如果负载因子为1就扩容
			if (_size == _tables.size())
			{
				//创建一个新的哈希表
				vector<Node*> newTables;
				size_t newSizes = _size == 0 ? 10 : 2 * _tables.size();

				//将每个元素初始化为空
				newTables.resize(__stl_next_prime(_tables.size()), nullptr);

				//将旧表结点插入到新表当中
				for (size_t i = 0; i < _tables.size(); i++)
				{
					Node* cur = _tables[i];

					while (cur)
					{
						//记录cur的下一个结点
						Node* next = cur->_next;
						//计算相应的哈希桶编号
						size_t hashi = hash(cur->_kv.first) % newTables.size();

						//将旧表结点移动值新表
						cur->_next = newTables[hashi];
						newTables[hashi] = cur;
						cur = next;
					}
					_tables[i] = nullptr;
				}
				_tables.swap(newTables);
			}
			//计算哈希桶编号
			size_t hashi = hash(kv.first) % _tables.size();

			//插入结点
			Node* newnode = new Node(kv);
			newnode->_next = _tables[hashi];
			_tables[hashi] = newnode;

			//元素个数++
			_size++;
			return true;
		}
		//查找
		Node* Find(const K& key)
		{
			//哈希表为空就返回空
			if (_tables.size() == 0)
			{
				return nullptr;
			}
			Hash hash;
			//计算哈希地址
			size_t hashi = hash(key) % _tables.size();
			Node* cur = _tables[hashi];
			//遍历哈希桶
			while (cur)
			{
				if ((cur->_kv.first) == key)
				{
					return cur;
				}
				cur = cur->_next;
			}
			return nullptr;
		}
		//删除
		bool Erase(const K& key)
		{
			//哈希表大小为0,删除失败
			if (_tables.size() == 0)
			{
				return false;
			}
			Hash hash;
			//计算哈希地址
			size_t hashi = hash(key) % _tables.size();

			Node* prev = nullptr;
			Node* cur = _tables[hashi];
			//遍历哈希桶,寻找删除结点是否存在
			while (cur)
			{
				if (hash(hash(cur->_kv.first)) == key)
				{
					if (prev)
					{
						prev->_next = cur->_next;
					}
					else
					{
						_tables[hashi] = cur->_next;
					}
					//删除该结点
					delete cur;
					_size--;

					return true;
				}

				prev = cur;
				cur = cur->_next;
			}
			//删除结点不存在,返回false
			return false;
		}

		size_t Size()
		{
			return _size;
		}

		size_t TableSize()
		{
			return _tables.size();
		}

		size_t BucketNum()
		{
			size_t num = 0;
			for (size_t i = 0; i < _tables.size(); i++)
			{
				if (_tables[i])
				{
					num++;
				}
			}
			return num;
		}
	private:
		vector<Node*> _tables;
		size_t _size = 0;
	};
}

哈希表模板参数的控制

unordered_set属于K模型,unordered_map属于KV模型,但是在底层上我们都是用一个哈希表来实现的,所以我们需要将哈希表的第二个参数设置为T。

template<class K, class T>
	struct HashNode
	{
		T _data;
		HashNode<T>* _next;

		//构造函数
		HashNode(const T& data)
			:_data(data)
			,_next(nullptr)
		{}
	};
	template<class K, class T, class Hash = HashFunc<K>>
	class HashTable
	{
		typedef HashNode<T> Node;
	public:
	//......
	private:
	vector<Node*> _tables;
	size_t _size = 0;
};

T模板参数可能只是键值Key,也可能是由Key和Value共同构成的键值对。如果是unordered_set容器,那么它传入底层红黑树的模板参数就是Key和Key:

template<class K, class Hash = HashFunc<K>>
class unorder_set
{
public:
	//...
private:
	HashBucket::HashTable<K, K, Hash> _ht;
};

如果是unordered_map容器,那么它传入底层红黑树的模板参数就是Key和Value:

template<class K, class V, class Hash = HashFunc<K>>
class unorder_map
{
public:
	//...
private:
	HashBucket::HashTable<K, pair<K, V>, Hash> _ht;
};

在这里插入图片描述

仿函数增加

对于unordered_set容器,我们需要进行键值比较就是对key值进行比较,也就是直接比较T就可以了,但是对于unordered_map容器来说,我们需要比较的是键值对<key,value>中的key,我们需要先将key提取出来,在进行比较。

所以,我们需要在上层unordered_set和unordered_map中各提供一个仿函数,根据传入的T类型分开进行比较操作:

map仿函数:

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

set仿函数:

template<class K, class Hash = HashFunc<K>>
class unorder_set
{
	struct SetKeyOfT
	{
		const K& operator()(const K& key)
		{
			return key;
		}
	};
public:
	//...
private:
	HashBucket::HashTable<K, K, Hash, SetKeyOfT> _ht;
};

在这里插入图片描述

正向迭代器实现

哈希表只存在正向迭代器,哈希表的正向迭代器实际上是对整个哈希表进行了封装:

//前置声明
template<class K, class T, class Hash, class KeyOfT>
class HashTable;

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

	
	Node* _node;
	HT* _pht;
}

*运算符重载

解引用操作就是返回单链表某个结点的数据:

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

->运算符重载

->操作就是返回数据的地址:

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

++运算符重载

哈希表中++其实就是寻找当前哈希桶中的该结点下一个结点,如果一个哈希桶中已经寻找完,就去下一个哈希桶中进行寻找,直到找到为止;

代码如下:

Self& operator++()
{
	//寻找该结点下一个结点点
	if (_node->_next)
	{
		//下一个结点不为空,就指向下一个结点
		_node = _node->_next;
	}
	else
	{
		Hash hash;
		KeyOfT kot;

		//为空就计算该哈希桶所处位置的哈希地址
		size_t i = hash(kot(_node->_data)) % _pht->_tables.size();

		//地址++就计算出下一个桶的位置
		i++;

		//继续循环寻找
		for (; i < _pht->_tables.size(); i++)
		{
			if (_pht->_tables[i])
			{
				_node = _pht->_tables[i];
				break;
			}
		}
		//找完整个哈希表,就指向nullptr
		if (i == _pht->_tables.size())
		{
			_node = nullptr;
		}
	}

	return *this;
}

!= 和 == 运算符重载

!= 和 ==就是判断是不是同一个结点:

//!=
bool operator!=(const Self& s)
{
	return _node != s._node;
}
//==
bool operator==(const Self& s)
{
	return _node == s._node;
}

begin()与end()实现

  1. begin函数返回哈希表当中第一个不为nullptr位置的正向迭代器。
  2. end函数返回哈希表当中最后一个位置下一个位置的正向迭代器,这里直接用空指针构造一个正向迭代器。
class HashTable
{
	typedef HashNode<T> Node;

	template<class K, class T, class Hash, class KeyOfT>
	friend struct __HashIterator;
public:
	typedef __HashIterator <K, T, Hash, KeyOfT> iterator;

	iterator begin()
	{
		//从前往后遍历整个数组
		for (size_t i = 0; i < _tables.size(); i++)
		{
			//找到不为空的位置并返回该位置迭代器
			if (_tables[i])
			{
				return iterator(_tables[i], this);
			}
		}
		//最后返回end();
		return end();
	}

	iterator end()
	{
		//返回一个为空的位置的迭代器
		return iterator(nullptr, this);
	}
}

unordered_set实现

template<class K, class Hash = HashFunc<K>>
class unordered_set
{
	struct SetKeyOfT
	{
		const K& operator()(const K& key)
		{
			return key;
		}
	};
public:
	typedef typename HashBucket::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:
	HashBucket::HashTable<K, K, Hash, SetKeyOfT> _ht;
};

unordered_map实现

template<class K, class V, class Hash = HashFunc<K>>
class unordered_map
{
	struct MapKeyOfT
	{
		const K& operator()(const pair<K, V>& kv)
		{
			return kv.first;
		}
	};
public:
	typedef typename HashBucket::HashTable <K, pair<K, V>, Hash, MapKeyOfT>::iterator iterator;

	iterator begin()
	{
		return _ht.begin();
	}

	iterator end()
	{
		return _ht.end();
	}

	pair<iterator, bool> insert(const K& key)
	{
		_ht.Insert(key);
	}

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

map/set 与 unordered_map/unordered_set对比

map/set 底层是使用红黑树实现的,unordered_map/unordered_set底层是用哈希表进行实现的,两者的底层实现是不同的,对于少量的数据,他们的增删查改没有区别,但是对于大量的数据unordered系列是要更胜一筹的,特别是对于查找来说,unordered系列基本可以一直保持高效率;

哈希表调整后代码

#pragma once

template<class K>
struct HashFunc
{
	size_t operator()(const K& key)
	{
		//所有类型都强转为size_t类型
		return (size_t)key;
	}
};

//模板特化
template<>
struct HashFunc<string>
{
	size_t operator()(const string& key)
	{
		size_t val = 0;
		for (auto ch : key)
		{
			val *= 131;
			val += ch;
		}

		return val;
	}
};

namespace HashBucket
{
	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 __HashIterator
	{
		typedef HashNode<T> Node;
		typedef HashTable <K, T, Hash, KeyOfT> HT;
		typedef __HashIterator <K, T, Hash, KeyOfT> Self;

		
		Node* _node;
		HT* _pht;

		//构造函数
		__HashIterator(Node* node, HT* pht)
			:_node(node)
			,_pht(pht)
		{}

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

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

		Self& operator++()
		{
			//寻找该结点下一个结点点
			if (_node->_next)
			{
				//下一个结点不为空,就指向下一个结点
				_node = _node->_next;
			}
			else
			{
				Hash hash;
				KeyOfT kot;

				//为空就计算该哈希桶所处位置的哈希地址
				size_t i = hash(kot(_node->_data)) % _pht->_tables.size();

				//地址++就计算出下一个桶的位置
				i++;

				//继续循环寻找
				for (; i < _pht->_tables.size(); i++)
				{
					if (_pht->_tables[i])
					{
						_node = _pht->_tables[i];
						break;
					}
				}
				//找完整个哈希表,就指向nullptr
				if (i == _pht->_tables.size())
				{
					_node = nullptr;
				}
			}

			return *this;
		}

		bool operator!=(const Self& s)
		{
			return _node != s._node;
		}

		bool operator==(const Self& s)
		{
			return _node == s._node;
		}
	};

	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 __HashIterator;
	public:
		typedef __HashIterator <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 end();
		}

		iterator end()
		{
			return iterator(nullptr, this);
		}

		~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;
			}
		}

		inline size_t __stl_next_prime(size_t n)
		{
			static const size_t __stl_num_primes = 28;
			static const size_t __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 (size_t i = 0; i < __stl_num_primes; ++i)
			{
				if (__stl_prime_list[i] > n)
				{
					return __stl_prime_list[i];
				}
			}

			return -1;
		}
		pair<iterator, bool> Insert(const T& data)
		{
			Hash hash;
			KeyOfT kot;
			//如果该键值对存在,就返回false
			iterator ret = Find((kot(data)));
			if (ret != end())
			{
				return make_pair(ret, false);
			}
			//如果负载因子为1就扩容
			if (_size == _tables.size())
			{
				//创建一个新的哈希表
				vector<Node*> newTables;
				size_t newSizes = _size == 0 ? 10 : 2 * _tables.size();

				//将每个元素初始化为空
				newTables.resize(__stl_next_prime(_tables.size()), nullptr);

				//将旧表结点插入到新表当中
				for (size_t i = 0; i < _tables.size(); i++)
				{
					Node* cur = _tables[i];

					while (cur)
					{
						//记录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;

			//元素个数++
			_size++;
			return make_pair(iterator(newnode, this), true);
		}
		//查找
		iterator Find(const K& key)
		{
			//哈希表为空就返回空
			if (_tables.size() == 0)
			{
				return end();
			}
			Hash hash;
			KeyOfT kot;
			//计算哈希地址
			size_t hashi = hash(key) % _tables.size();
			Node* cur = _tables[hashi];
			//遍历哈希桶
			while (cur)
			{
				if (kot(cur->_data) == key)
				{
					return iterator(cur, this);
				}
				cur = cur->_next;
			}
			return end();
		}
		//删除
		bool Erase(const K& key)
		{
			//哈希表大小为0,删除失败
			if (_tables.size() == 0)
			{
				return false;
			}
			Hash hash;
			//计算哈希地址
			size_t hashi = hash(key) % _tables.size();

			Node* prev = nullptr;
			Node* cur = _tables[hashi];
			//遍历哈希桶,寻找删除结点是否存在
			while (cur)
			{
				if (hash(kot(cur->_data)) == key)
				{
					if (prev)
					{
						prev->_next = cur->_next;
					}
					else
					{
						_tables[hashi] = cur->_next;
					}
					//删除该结点
					delete cur;
					_size--;

					return true;
				}

				prev = cur;
				cur = cur->_next;
			}
			//删除结点不存在,返回false
			return false;
		}
	private:
		vector<Node*> _tables;
		size_t _size = 0;
	};
}

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

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

相关文章

python 自(3)1使用urlencode多个参数请求使用 2百度翻译post请求post无法添加路径 3百度翻译全部数据获取 4豆瓣get请

1 使用urlencode 多个参数请求使用 # 使用urlencode 多个参数请求使用 # https://www.baidu.com/s?wd周杰伦&sex男 网页 import urllib.request import urllib.parsebase_url https://www.baidu.com/s?data {wd: 周杰伦,sex: 男,sing:歌曲 }new_data urllib.par…

牛客: BM3 链表中的节点每k个一组翻转

牛客: BM3 链表中的节点每k个一组翻转 文章目录 牛客: BM3 链表中的节点每k个一组翻转题目描述题解思路题解代码 题目描述 题解思路 用一个[]int保存一组节点的val,一个快节点先遍历k个节点将节点的val顺序保存在[]int中,然后慢节点再遍历k个节点,逆序将[]int的val设置给节点的…

北斗导航 | 基于奇异值分解的接收机自主完好性监测算法

===================================================== github:https://github.com/MichaelBeechan CSDN:https://blog.csdn.net/u011344545 ===================================================== 基于奇异值分解的接收机自主完好性监测算法 摘 要:基于最小二乘法残差…

Python Opencv实践 - 视频文件操作

参考资料&#xff1a; 视频处理VideoCapture类---OpenCV-Python开发指南&#xff08;38&#xff09;_python opencv videocapture_李元静的博客-CSDN博客 OpenCV VideoCapture.get()参数详解 - 简书FOURCC四字符码对照表_4fvcc_Kellybook的博客-CSDN博客 import cv2 as cv im…

【计算机网络】传输层协议——TCP(下)

文章目录 1. 三次握手三次握手的本质是建立链接&#xff0c;什么是链接&#xff1f;整体过程三次握手过程中报文丢失问题为什么2次握手不可以&#xff1f;为什么要三次握手&#xff1f; 2. 四次挥手整体过程为什么要等待2MSL 3. 流量控制4. 滑动窗口共识滑动窗口的一般情况理解…

星际争霸之小霸王之小蜜蜂(十三)--接着奏乐接着舞

系列文章目录 星际争霸之小霸王之小蜜蜂&#xff08;十二&#xff09;--猫有九条命 星际争霸之小霸王之小蜜蜂&#xff08;十一&#xff09;--杀杀杀 星际争霸之小霸王之小蜜蜂&#xff08;十&#xff09;--鼠道 星际争霸之小霸王之小蜜蜂&#xff08;九&#xff09;--狂鼠之…

国家网络安全周 | 天空卫士荣获“2023网络安全优秀创新成果大赛优胜奖”

9月11日上午&#xff0c;四川省2023年国家网络安全宣传周在泸州开幕。在开幕式上&#xff0c;为2023年网络安全优秀创新成果大赛——成都分站赛暨四川省“熊猫杯”网络安全优秀作品大赛中获奖企业颁奖&#xff0c;天空卫士银行数据安全方案获得优秀解决方案奖。 本次比赛由四川…

免费好用的天翎bpm流程引擎,实现生产管理系统

1.什么是生产管理系统 针对中小型制造企业的生产应用而开发&#xff0c;能够帮助企业建立一个规范准确即时的生产数据库&#xff0c;同时实现轻松、规范、细致的生产业务、库存业务一体化管理工作。提高管理效率&#xff08;企业管理的科学方法&#xff09;、掌握及时、准确、全…

Mysql高级——索引创建和使用

索引的创建 1. 索引的声明与使用 1.1 索引的分类 MySQL的索引包括普通索引、唯一性索引、全文索引、单列索引、多列索引和空间索引等。 从功能逻辑上说&#xff0c;索引主要有 4 种&#xff0c;分别是普通索引、唯一索引、主键索引、全文索引。 按照物理实现方式&#xff…

Spring之IOC容器(依赖注入)基本介绍基本配置多模块化

标题一&#xff1a;什么是spring&#xff0c;它能够做什么? Spring是一个开源框架&#xff0c;它由Rod Johnson创建。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而&#xff0c;Spring的用途不仅限于服务器端的…

【计算机视觉 | CNN】Image Model Blocks的常见算法介绍合集(一)

文章目录 一、Residual Block二、Bottleneck Residual Block三、Dense Block四、Squeeze-and-Excitation Block五、Inception Module六、Non-Local Block七、Spatial Attention Module八、Spatial Transformer九、ResNeXt Block十、Fire Module十一、Inception-v3 Module十二、…

数据结构与算法(C语言版)P2---线性表之顺序表

前景回顾 #mermaid-svg-sXTObkmwPR34tOT4 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-sXTObkmwPR34tOT4 .error-icon{fill:#552222;}#mermaid-svg-sXTObkmwPR34tOT4 .error-text{fill:#552222;stroke:#552222;}#…

拥有这个中文版CustomGPT,你也能定制自己的AI问答机器人

人工智能技术的快速发展为各行各业带来了前所未有的机会&#xff0c;其中之一就是定制化的问答机器人。这些机器人可以用于客户支持、知识管理、虚拟助手等多个领域&#xff0c;帮助企业提高效率&#xff0c;提供更好的用户体验。很多人可能都知道通过CustomGPT能够设计自己的人…

Golang使用sqlx报错max_prepared_stmt_count超过16382

文章目录 背景mysql的预处理查看实例预处理详情com_stmt_prepare开启performance_schema 本地查看预处理语句 预处理语句飙升的原因生成预处理语句但是不close执行sql过程中发生错误 go服务分析抓包分析发送给mysql的包debug查看预处理细节sqlx发送statement command指令sqlx关…

伦敦银时走势与获利机会

交易时间灵活、资金杠杆充沛是伦敦银交易的主要优势&#xff0c;投资者应该充分利用这个品种的制度优势&#xff0c;结合自己个人的作息时间&#xff0c;在工作、投资与生活三者之间取得平衡的前提下&#xff0c;借助国际白银市场的波动&#xff0c;通过交易逐步实现自己的财富…

外贸电商商品如何做好上架工作?

跨境电商业务的蓬勃发展已经成为互联网行业的热点话题之一。不论是将海外货源卖回国内&#xff0c;还是通过国内货源销往海外&#xff0c;跨境电商平台都面临着如何实现商品上架的关键问题。在这篇文章中&#xff0c;将探讨成功上架商品的关键步骤。 一、准备好接口。 跨境电商…

【LangChain系列 10】Prompt模版——Message的partial用法

原文地址&#xff1a;【LangChain系列 10】Prompt模版——Message的partial用法 本文速读&#xff1a; 字符串partial 方法partial partial是什么意思呢&#xff1f;简单来说&#xff1a;将一个prompt模版传入部分变量值而生成一个新的prompt模版&#xff0c;当使用新的promp…

小技巧!Python生成excel文件的三种方式!

在我们做平常工作中都会遇到操作excel&#xff0c;那么今天写一篇&#xff0c;如何通过python操作excel。当然python操作excel的库有很多&#xff0c;比如pandas&#xff0c;xlwt/xlrd&#xff0c;openpyxl等&#xff0c;每个库都有不同的区别&#xff0c;具体的区别&#xff0…

递归路由,怎么递归的?BGP4+

问题 R2上去往5&#xff1a;&#xff1a;5的递归路由怎么生成的&#xff1f;&#xff1f;&#xff1f; BGP4路由表 Destination : 5:: PrefixLength : 64 NextHop : 4::4 Preference : 255 Cost : …

sed命令在Mac和Linux下的不同

问题 &#xff08;1&#xff09;Windows系统里&#xff0c;文件每行结尾是<回车><换行>, \r\n &#xff08;2&#xff09;Mac系统里&#xff0c; 文件每行结尾是<回车>&#xff0c;即\r &#xff08;3&#xff09;Unix系统里&#xff0c; 文件每行…