用红黑树封装实现map与set

news2024/10/5 13:55:03

红黑树

红黑树 ,是一种 二叉搜索树 ,但 在每个结点上增加一个存储位表示结点的颜色,可以是 Red
Black 。 通过对 任何一条从根到叶子的路径上各个结点着色方式的限制,红黑树确保没有一条路
径会比其他路径长出俩倍 ,因而是 接近平衡
对比AVL树的严格平衡(左右子树高度差不超过1),需要更多的旋转才能控制这个高度
红黑树是近似平衡(最长路径不超过最短路径的2倍) 降低了插入和旋转的次数,
所以在经常进行增删的结构中性能比 AVL 树更优,而且红黑树实现比较简单,所以实际运用中红
黑树更多

红黑树的性质 

1. 每个结点不是 红色 就是黑色
2. 根节点 黑色  
3. 如果一个节点是红色的,则它的两个孩子结点是黑色的 ,即 不能出现连续的红节点
    父子节点:黑+黑  黑+红 红+黑
4. 对于每个结点,从该结点到其所有后代叶结点的简单路径上,均 包含相同数目的黑色结点
    即 每条路径都包含相同数量的黑节点 
5. 每个叶子结点都是黑色的 ( 此处的叶子结点指的是空结点 )
    即NIL节点,方便数路径,不容易出错

 

红黑树的插入

 新增节点的颜色默认给红色

因为新增节点若为黑色节点,插入后会影响所有路径(红黑树的性质规定每条路径必须有相同数量的黑色节点)

而新增插入红色节点只会影响父节点,(父子节点的组合:黑+黑,黑+红,红+黑)

(若父节点为黑,则无影响,若父节点为红,则有连续的红节点,需要调整,下面会讲)

红黑树节点的设计:

enum Colour
{
	RED,
	BLACK
};

template<class T> // T可以是set的K,可以是map的pair<K,V> 
struct RBTreeNode
{
	RBTreeNode<T>* _left;
	RBTreeNode<T>* _right; 
	RBTreeNode<T>* _parent;

	T _data;
	Colour _col;

	RBTreeNode(const T& data)
		:_left(nullptr)
		,_right(nullptr)
		,_parent(nullptr)
		,_data(data)
		,_col(RED)//新增节点默认给红色
	{}
};
红黑树是在二叉搜索树的基础上加上其平衡限制条件,故而红黑树的插入分为两步:
1 插入新增节点
2 判断新增节点插入后是否需要调整红黑树
(新增节点可能会导致连续红节点的出现,破坏了红黑树的规则)
什么时候需要调整红黑树:出现了连续的红节点,即新增节点的父节点为红色节点时
(新增节点默认为红,若父节点为黑,则没有违反红黑树的任何规则,插入完成后无需处理)
约定 :cur 为当前节点, p 为父节点, g 为祖父节点, u 为叔叔节点
红黑树的调整关键看叔叔节点
情况一 : cur 为红, p 为红, g 为黑, u存在且为红
(因为在cur插入之前,没有违反红黑树的任何规则,所以当p为红时,g一定为黑,不可能出现连续的红色节点)
解决方式 :将 p,u 改为黑, g 改为红,然后把 g 当成 cur ,继续向上调整

情况二: cur为红,p为红,g为黑,u不存在/u存在且为黑  

在这种情况下,单纯变色无法解决问题,需要旋转+变色

解决方案:旋转(单选/双旋)+变色

需要 单旋 时的情况:
p g 的左孩子, cur p 的左孩子,则进行右单旋
p g 的右孩子, cur p 的右孩子,则进行左单旋
p g 变色 -- p变黑,g变红

需要双旋时的情况:

p g 的左孩子, cur p 的右孩子,则进行左右双旋
(先对p节点所在子树左单旋,再对g节点所在子树右单旋)
p g 的右孩子, cur p 的左孩子,则进行右左双旋
(先对p节点所在子树右单旋,再对g节点所在子树左单旋)
cur,g变色-- cur变黑,g变红

代码实现:

pair<Node*, bool> Insert(const T& data)
	{
		//插入一个红色节点
		if (_root == nullptr)
		{
			_root = new Node(data);
			_root->_col = BLACK;
			return make_pair(_root, true);
		}
			
		Node* cur = _root;
		Node* parent = nullptr;
		KeyOfT kot;

		while (cur)
		{
			if (kot(cur->_data) < kot(data))
			{
				parent = cur;
				cur = cur->_right;
			}
			else if (kot(cur->_data) > kot(data))
			{
				parent = cur;
				cur = cur->_left;
			}
			else
			{
				return make_pair(cur, false);
			}
		}

		//新增节点给红色
		cur = new Node(data);
		Node* newnode = cur;
		if (kot(parent->_data)>kot(data))
		{
			parent->_left = cur;
			cur->_parent = parent;
		}
		else
		{
			parent->_right = cur;
			cur->_parent = parent;
		}

		//红黑树调整--有连续的红节点
		while (parent && parent->_col == RED)
		{
			Node* grandfather = parent->_parent;

			if (parent == grandfather->_left)
			{
				//     g
				//   p   u
				// c
				Node* uncle = grandfather->_right;
				if (uncle && uncle->_col == RED)//uncle存在且为红--变色
				{
					parent->_col = uncle->_col = BLACK;
					grandfather->_col = RED;

					//继续向上调整
					cur = grandfather;
					parent = cur->_parent;
				}
				else//uncle不存在或者存在且为黑--旋转+变色
				{
					if (cur == parent->_left)//右单旋
					{
						//     g
						//   p
						// c
						RotateR(grandfather);
						parent->_col = BLACK;
						grandfather->_col = RED;
					}
					else//左右双旋
					{
						//     g
						//   p
						//     c
						RotateL(parent);
						RotateR(grandfather);
						cur->_col = BLACK;
						grandfather->_col = RED;
					}
					break;
				}
			}
			else//parent == grandfather->_right
			{
				//     g
				//   u   p 
				//          c
				Node* uncle = grandfather->_left;
				if (uncle && uncle->_col == RED)//uncle存在且为红--变色
				{
					parent->_col = uncle->_col = BLACK;
					grandfather->_col = RED;

					//继续向上调整
					cur = grandfather;
					parent = cur->_parent;
				}
				else//uncle不存在或者存在且为黑--旋转+变色
				{
					if (cur == parent->_right)//左单旋
					{
						RotateL(grandfather);
						parent->_col = BLACK;
						grandfather->_col = RED;
					}
					else//右左双旋
					{
						//     g
						//   u   p 
						//     c
						RotateR(parent);
						RotateL(grandfather);
						cur->_col = BLACK;
						grandfather->_col = RED;
					}
					break;
				}
			}
		}
		_root->_col = BLACK;
		return make_pair(newnode, true);
	}

需要用到的左单旋 右单旋:(在AVL数的代码实现中有具体讲解)

void RotateL(Node* parent)
	{
		Node* subR = parent->_right;
		Node* subRL = subR->_left;

		parent->_right = subRL;
		if (subRL)
		{
			subRL->_parent = parent;
		}

		Node*parentParent = parent->_parent;
		parent->_parent = subR;
		subR->_left = parent;
		if (_root == parent)
		{
			_root = subR;
			subR->_parent = nullptr;
		}
		else
		{
			if (parentParent->_left == parent)
			{
				parentParent->_left = subR;
			}
			else
			{
				parentParent->_right = subR;
			}
			subR->_parent = parentParent;
		}
	}

	void RotateR(Node* parent)
	{
		Node* subL = parent->_left;
		Node* subLR = subL->_right;

		parent->_left = subLR;
		if (subLR)
			subLR->_parent = parent;

		Node* parentParent = parent->_parent;
		subL->_right = parent;
		parent->_parent = subL;

		if (_root == parent)
		{
			_root = subL;
			subL->_parent = nullptr;
		}
		else
		{
			if (parentParent->_left == parent)
			{
				parentParent->_left = subL;
			}
			else
			{
				parentParent->_right = subL;
			}
			subL->_parent = parentParent;
		}
	}


 红黑树的验证

1. 验证 其是否满足二叉搜索树 ( 中序遍历是否为有序序列 )
2. 验证 其是否满足红黑树的性质
bool IsBalance()
	{
		//检查根节点
		if (_root == nullptr)
			return true;

		if (_root->_col == RED)
			return false;
		//检查是否有连续的红节点+每条路径的黑色节点数目是否一样
		
		int refVal = 0;//参考值
		Node* cur = _root;
		while (cur)//以最左边的路径上的黑色节点数目为参考值
		{
			if (cur->_col == BLACK)
				refVal++;
			cur = cur->_left;
		}

		int blacknum = 0;
		return  Check(_root, refVal, blacknum);

	}

	bool Check(Node* root, const int refVal,int blacknum)
	{
		if (root == nullptr)
		{
			if (blacknum != refVal)
			{
				cout << "存在黑色节点数量不相等的路径" << endl;
				return false;
			}
			return true;
		}

		if (root->_col == BLACK)//节点为黑色--统计
		{
			blacknum++;
		}
		
		if(root->_col == RED && root->_parent->_col == RED)//节点为红色--检查
		{
			
			cout << "有连续的红色节点" << endl;
			return false;
		}

		return Check(root->_left, refVal, blacknum)
			&& Check(root->_right, refVal, blacknum);
	}

红黑树模拟实现map与set

代码:

MyMap.h

#pragma once
#include"RBTree.h"

namespace djx
{
	template<class K,class V>
	class map
	{
	public:
		struct MapKeyOfT//获取关键字K,map存储的是pair<K,V>
		{
			const K& operator()(const pair<K, V>&kv)
			{
				return kv.first;
			}
		};

		// 对类模板取内嵌类型,加typename告诉编译器这里是类型
		typedef typename RBTree<K, pair<const K, V> ,MapKeyOfT>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V> ,MapKeyOfT>::const_iterator const_iterator;

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

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

		V& operator[](const K&key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;//ret.first是迭代器,能够找到节点
		}

		pair<iterator, bool> insert(const pair<K, V>&kv)
		{
			return _t.Insert(kv);
		}

	private:
		RBTree<K, pair<const K, V> ,MapKeyOfT> _t;//封装红黑树
	};
}

MySet.h

#pragma once
#include"RBTree.h"

namespace djx
{
	template<class K>
	class set
	{
	public:
		struct SetKeyOfT//仿函数,返回关键字K,set存储的就是K
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};

		typedef typename RBTree<K, K,SetKeyOfT>::const_iterator iterator;//set中的元素不可被修改,所以普通迭代器就用const_iterator来实现
		typedef typename RBTree<K, K, SetKeyOfT>::const_iterator const_iterator;

		iterator begin()const
		{
			return _t.begin();
		}

		iterator end() const
		{
			return _t.end();
		}

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

	private:
		RBTree<K, K, SetKeyOfT> _t;
	};
}

RBTree.h

#pragma once

// set ->key
// map ->key/value
enum Colour
{
	RED,
	BLACK
};

template<class T>
struct RBTreeNode//节点
{
	RBTreeNode<T>* _left;
	RBTreeNode<T>* _right; 
	RBTreeNode<T>* _parent;

	T _data;
	Colour _col;

	RBTreeNode(const T& data)
		:_left(nullptr)
		,_right(nullptr)
		,_parent(nullptr)
		,_data(data)
		,_col(RED)
	{}
};

template<class T,class Ref,class Ptr>
struct __TreeIterator//迭代器
{
	typedef RBTreeNode<T> Node;
	typedef __TreeIterator<T, Ref, Ptr> Self;
	Node* _node;

	__TreeIterator(Node* node)
		:_node(node)
	{}


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

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

	Self& operator++()
	{
		//顺序:左 中 右
		if (_node->_right)//这颗子树没有走完--找右子树的最左节点
		{
			Node* cur = _node->_right;
			while (cur->_left)
			{
				cur = cur->_left;
			}
			_node = cur;
		}
		else//这颗子树已经走完--找一个祖先(这个子树是它左孩子的祖先)
		{
			Node* cur = _node;
			Node* parent = cur->_parent;
			while (parent && parent->_right == cur)
			{
				cur = parent;
				parent = cur->_parent;
			}
			_node = parent;
		}
		return *this;
	}

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

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

template<class K,class T,class KeyOfT>
class RBTree
{
	typedef RBTreeNode<T> Node;
public:
	typedef __TreeIterator<T, T&, T*> iterator;
	typedef __TreeIterator<T, const T&, const T*> const_iterator;

	iterator begin()//红黑树中序序列得到有序序列,begin()可设计成最左节点的迭代器
	{
		Node* cur = _root;
		while (cur && cur->_left)
		{
			cur = cur->_left;
		}
		return iterator(cur);
	}

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

	const_iterator begin()const
	{

		Node* cur = _root;
		while (cur&& cur->_left)
		{
			cur = cur->_left;
		}
		return const_iterator(cur);
	}

	const_iterator end()const
	{
		return const_iterator(nullptr);
	}
    
    //返回值不能是pair<iterator, bool>,因为set的普通迭代器实际也是const_iterator,set设计insert时要返回的pair<iterator, bool> 实际是pair<const_iterator, bool> ,而封装红黑树,复用红黑树的Insert(返回值若是pair<iterator, bool>,红黑树的普通迭代器就是普通迭代器,那么因为普通迭代器iterator不能转成const_iterator,所以代码会报错)
设计成pair<Node*, bool>就很好,节点指针Node*可以通过const_iterator迭代器的构造函数完成转变
	pair<Node*, bool> Insert(const T& data)
	{
		//插入一个红色节点
		if (_root == nullptr)
		{
			_root = new Node(data);
			_root->_col = BLACK;
			return make_pair(_root, true);
		}
			
		Node* cur = _root;
		Node* parent = nullptr;
		KeyOfT kot;

		while (cur)
		{
			if (kot(cur->_data) < kot(data))
			{
				parent = cur;
				cur = cur->_right;
			}
			else if (kot(cur->_data) > kot(data))
			{
				parent = cur;
				cur = cur->_left;
			}
			else
			{
				return make_pair(cur, false);
			}
		}

		//新增节点给红色
		cur = new Node(data);
		Node* newnode = cur;
		if (kot(parent->_data)>kot(data))
		{
			parent->_left = cur;
			cur->_parent = parent;
		}
		else
		{
			parent->_right = cur;
			cur->_parent = parent;
		}

		//红黑树调整--有连续的红节点
		while (parent && parent->_col == RED)
		{
			Node* grandfather = parent->_parent;

			if (parent == grandfather->_left)
			{
				//     g
				//   p   u
				// c
				Node* uncle = grandfather->_right;
				if (uncle && uncle->_col == RED)//uncle存在且为红--变色
				{
					parent->_col = uncle->_col = BLACK;
					grandfather->_col = RED;

					//继续向上调整
					cur = grandfather;
					parent = cur->_parent;
				}
				else//uncle不存在或者存在且为黑--旋转+变色
				{
					if (cur == parent->_left)//右单旋
					{
						//     g
						//   p
						// c
						RotateR(grandfather);
						parent->_col = BLACK;
						grandfather->_col = RED;
					}
					else//左右双旋
					{
						//     g
						//   p
						//     c
						RotateL(parent);
						RotateR(grandfather);
						cur->_col = BLACK;
						grandfather->_col = RED;
					}
					break;
				}
			}
			else//parent == grandfather->_right
			{
				//     g
				//   u   p 
				//          c
				Node* uncle = grandfather->_left;
				if (uncle && uncle->_col == RED)//uncle存在且为红--变色
				{
					parent->_col = uncle->_col = BLACK;
					grandfather->_col = RED;

					//继续向上调整
					cur = grandfather;
					parent = cur->_parent;
				}
				else//uncle不存在或者存在且为黑--旋转+变色
				{
					if (cur == parent->_right)//左单旋
					{
						RotateL(grandfather);
						parent->_col = BLACK;
						grandfather->_col = RED;
					}
					else//右左双旋
					{
						//     g
						//   u   p 
						//     c
						RotateR(parent);
						RotateL(grandfather);
						cur->_col = BLACK;
						grandfather->_col = RED;
					}
					break;
				}
			}
		}
		_root->_col = BLACK;
		return make_pair(newnode, true);
	}

	iterator Find(const K& key)
	{
		//...

		return end();
	}

	void RotateL(Node* parent)
	{
		Node* subR = parent->_right;
		Node* subRL = subR->_left;

		parent->_right = subRL;
		if (subRL)
		{
			subRL->_parent = parent;
		}

		Node*parentParent = parent->_parent;
		parent->_parent = subR;
		subR->_left = parent;
		if (_root == parent)
		{
			_root = subR;
			subR->_parent = nullptr;
		}
		else
		{
			if (parentParent->_left == parent)
			{
				parentParent->_left = subR;
			}
			else
			{
				parentParent->_right = subR;
			}
			subR->_parent = parentParent;
		}
	}

	void RotateR(Node* parent)
	{
		Node* subL = parent->_left;
		Node* subLR = subL->_right;

		parent->_left = subLR;
		if (subLR)
			subLR->_parent = parent;

		Node* parentParent = parent->_parent;
		subL->_right = parent;
		parent->_parent = subL;

		if (_root == parent)
		{
			_root = subL;
			subL->_parent = nullptr;
		}
		else
		{
			if (parentParent->_left == parent)
			{
				parentParent->_left = subL;
			}
			else
			{
				parentParent->_right = subL;
			}
			subL->_parent = parentParent;
		}
	}



	bool IsBalance()//红黑树的验证
	{
		//检查根节点
		if (_root == nullptr)
			return true;

		if (_root->_col == RED)
			return false;
		//检查是否有连续的红节点+每条路径的黑色节点数目是否一样
		
		int refVal = 0;//参考值
		Node* cur = _root;
		while (cur)//以最左边的路径上的黑色节点数目为参考值
		{
			if (cur->_col == BLACK)
				refVal++;
			cur = cur->_left;
		}

		int blacknum = 0;
		return  Check(_root, refVal, blacknum);

	}

	bool Check(Node* root, const int refVal,int blacknum)
	{
		if (root == nullptr)
		{
			if (blacknum != refVal)
			{
				cout << "存在黑色节点数量不相等的路径" << endl;
				return false;
			}
			return true;
		}

		if (root->_col == BLACK)//节点为黑色--统计
		{
			blacknum++;
		}
		
		if(root->_col == RED && root->_parent->_col == RED)//节点为红色--检查
		{
			
			cout << "有连续的红色节点" << endl;
			return false;
		}

		return Check(root->_left, refVal, blacknum)
			&& Check(root->_right, refVal, blacknum);
	}

	int Height()
	{
		return _Height(_root);
	}

	int _Height(Node* root)
	{
		if (root == nullptr)
			return 0;

		int leftHeight = _Height(root->_left);
		int rightHeight = _Height(root->_right);
		return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
	}

	size_t Size()
	{
		return _Size(_root);
	}

	size_t _Size(Node* root)
	{
		if (root == nullptr)
			return 0;

		return _Size(root->_left) + _Size(root->_right) + 1;
	}
private:
	Node* _root = nullptr;
};

处理设计红黑树Insert函数返回值的细节:

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

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

相关文章

新品发布 | 多通道总线记录仪TLog1004,是你期待的吗?

新品发布 2024年1月12日&#xff0c;同星智能又发布一款多通道 CAN &#xff08;FD&#xff09;总线、LIN 总线接口logger设备&#xff0c;此款产品在TLog1002基础上进行了升级&#xff0c;同时内置 3 路数字输入和 2 路数字输出&#xff0c;便于多种信号测量和系统集成。可以满…

12- OpenCV:算子(Sobel和Laplance) 和Canny边缘检测 详解

目录 一、Sobel算子 1、卷积应用-图像边缘提取 2、Sobel算子&#xff08;索贝尔算子&#xff09; 3、相关的API&#xff08;代码例子&#xff09; 二、Laplance算子 1、理论 2、API使用&#xff08;代码例子&#xff09; 三、Canny边缘检测 1、Canny算法介绍 2、API使…

Vulnhub-LORD OF THE ROOT: 1.0.1

一、信息收集 端口扫描、发现只开了22端口 连接ssh后提示端口碰撞&#xff1a; 端口敲门是一种通过在一组预先指定的关闭端口上产生连接请求&#xff0c;从外部打开防火墙上的端口的方法。一旦收到正确地连接请求序列&#xff0c;防火墙规则就会被动态修改&#xff0c;以允许…

eNSP学习——配置通过Telnet登陆系统

实验内容&#xff1a; 模拟公司网络场景。R1是机房的设备&#xff0c;办公区与机房不在同一楼层&#xff0c;R2和R3模拟员工主机&#xff0c; 通过交换机S1与R1相连。 为了方便用户的管理&#xff0c;需要在R1上配置Telnet使员工可以在办公区远程管理机房设备。 为…

探究Java中的链表

引言&#xff1a; 在Java编程中&#xff0c;链表是一种常见的数据结构&#xff0c;具有灵活的内存管理和动态的元素插入与删除能力。本篇博客将深入探讨链表的结构和概念&#xff0c;比较链表与顺序表的区别&#xff0c;介绍Java中LinkedList的常用函数并通过示例说明LinkedLis…

2023:既是结束也是开始

2023年注定是不平凡的一年&#xff0c;这一年真的经历了很多事&#xff0c;包括学习、生活、工作等等&#xff0c;上半年忙着毕业以及一些其他的事情&#xff0c;很多挖的坑都没来得及填&#xff0c;下半年研一开学以后终于有了足够的时间学习&#xff0c;接下来就用这篇文章来…

【linux】Debian10.0配置vsftpd

一、基本步骤 在 Debian 10 (Buster) 上要配置 vsftpd (Very Secure FTP Daemon)&#xff0c;请按照以下步骤操作&#xff1a; 1. 安装 vsftpd: sudo apt update sudo apt install vsftpd 2. 在启动配置之前&#xff0c;建议备份原始的配置文件: sudo cp /etc/vsftpd.con…

python解释器多版本设置

当你的项目很多&#xff0c;切python版本不一样时&#xff0c;如何为每个项目设置不同的python解释器版本和虚拟环境&#xff1a; 1、安装pyenv brew install pyenv 配置 Pyenv&#xff1a; 将以下内容添加到你的 shell 配置文件&#xff08;如 ~/.bashrc、~/.zshrc 或 ~/.ba…

【c++】初始c++

1. 什么是C 下图就是我们c的祖师爷 C语言是结构化和模块化的语言&#xff0c;适合处理较小规模的程序。对于复杂的问题&#xff0c;规模较大的程序&#xff0c;需要高度的抽象和建模时&#xff0c;C语言则不合适。为了解决软件危机&#xff0c; 20世纪80年代&#xff0c; 计算…

Ubuntu使用docker-compose安装chatGPT

ubuntu环境搭建专栏&#x1f517;点击跳转 Ubuntu系统环境搭建&#xff08;十五&#xff09;——使用docker-compose安装chatGPT Welcome to the AI era! 使用docker compose安装 在/usr/local文件夹下创建chatgpt mkdir chatgpt创建docker-compose.yaml vim docker-compos…

P2P DMA并不是所有场景都会有性能提升

P2P (Peer-to-Peer) DMA技术理论上可以带来性能提升&#xff0c;特别是在特定的工作负载和场景下。例如&#xff0c;当两个高速设备&#xff08;如GPU与NVMe SSD&#xff09;需要频繁进行大量数据交换时&#xff0c;通过P2P DMA&#xff0c;数据可以直接在设备间传输&#xff0…

【Linux】常见指令解析下

目录 前言1. cp指令&#xff08;重要&#xff09;2. mv指令 &#xff08;重要&#xff09;3. cat指令4. more指令5. less指令 &#xff08;重要&#xff09;6. head指令7. tail指令8. 时间相关的指令8.1 data显示8.2 时间戳 9. cal指令10. find指令&#xff08;非常重要&#x…

[绍棠] docxtemplater实现纯前端导出word

1.下载需要的依赖 2.util文件夹下创建doc.js文件 doc.js import docxtemplater from docxtemplater import PizZip from pizzip import JSZipUtils from jszip-utils import { saveAs } from file-saver import ImageModule from "docxtemplater-image-module-free"…

TCP服务器最多支持多少客户端连接

目录 一、理论数值 二、实际部署 参考 一、理论数值 首先知道一个基础概念&#xff0c;对于一个 TCP 连接可以使用四元组&#xff08;src_ip, src_port, dst_ip, dst_port&#xff09;进行唯一标识。因为服务端 IP 和 Port 是固定的&#xff08;如下图中的bind阶段&#xff0…

利用HTML+CSS+JS打造炫酷时钟网页的完整指南

引言 在现代Web开发中&#xff0c;制作一个引人注目的时钟网页是一种常见而令人愉悦的体验。本文将介绍如何使用HTML、CSS和JavaScript来创建一个炫酷的时钟网页&#xff0c;通过这个项目&#xff0c;你将学到如何结合这三种前端技术&#xff0c;制作一个动态且美观的时钟效果…

SpringMVC数据校验

导包 配置springmvc.xml <bean id"validator" class" org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"><property name"providerClass" value"org.hibernate.validator.HibernateValidator ">…

React16源码: React中的renderRoot的源码实现

renderRoot 1 &#xff09;概述 renderRoot 是一个非常复杂的方法这个方法里处理很多各种各样的逻辑, 它主要的工作内容是什么&#xff1f;A. 它调用 workLoop 进行循环单元更新 遍历整个 Fiber Tree&#xff0c;把每一个组件或者 dom 节点对应的Fiber 节点拿出来单一的进行更…

烟火检测AI边缘计算智能分析网关V4如何通过ssh进行服务器远程运维

智能分析网关V4是一款高性能、低功耗的AI边缘计算硬件设备&#xff0c;它采用了BM1684芯片&#xff0c;集成高性能8核ARM A53&#xff0c;主频高达2.3GHz&#xff0c;并且INT8峰值算力高达17.6Tops&#xff0c;FB32高精度算力达到2.2T&#xff0c;每个摄像头可同时配置3种算法&…

启动低轨道卫星LEO通讯产业与6G 3GPP NTN标准

通讯技术10年一个大跃进&#xff0c;从1990年的2G至2000年的3G网路&#xff0c;2010年的4G到近期2020年蓬勃发展的5G&#xff0c;当通讯技术迈入融合网路&#xff0c;当前的 5G 技术不仅可提供高频宽、低延迟&#xff0c;同时可针对企业与特殊需求以 5G 专网的模式提供各式服务…

vue-微信H5-拍照和视频,加人像框

图片拍照: <template><div><v-easy-camera:fullscreen"true"ref"easyCamera"v-model"pictureData.picture"class"main-camera"><template #header><div class"top"><van-imageclass"…