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

C++提高笔记(六)---STL函数对象、STL常用算法(遍历、查找)

1、STL-函数对象

1.1函数对象

1.1.1函数对象概念

概念:

重载函数调用操作符的类,其对象常称为函数对象

函数对象使用重载的()时,行为类似函数调用,也叫仿函数

本质:函数对象(仿函数)是一个,不是一个函数

1.1.2 函数对象使用

特点:

函数对象在使用时,可以像普通函数那样调用,可以有参数,可以有返回值

函数对象超出普通函数的概念,函数对象内部可以有自己的状态

函数对象可以作为参数传递

#include <iostream>
using namespace std;
#include<string>
//函数对象(仿函数)
//函数对象在使用时,可以像普通函数那样调用,可以有参数,可以有返回值
//函数对象超出普通函数的概念,函数对象内部可以有自己的状态
//函数对象可以作为参数传递
class MyAdd
{
public:int operator()(int v1, int v2){return v1 + v2;}
};
//1、函数对象在使用时,可以像普通函数那样调用,可以有参数,可以有返回值
void test01()
{MyAdd myadd;cout << myadd(10, 10) << endl;
}
//2、函数对象超出普通函数的概念,函数对象内部可以有自己的状态
class MyPrint
{
public:MyPrint(){this->count = 0;}void operator()(string text){cout << text << endl;this->count++;}int count;//内部自己状态
};
void test02()
{MyPrint myprint;myprint("hello world!");myprint("hello world!");myprint("hello world!");myprint("hello world!");cout << "MyPrint调用的次数:" << myprint.count << endl;
}
//3、函数对象可以作为参数传递
void doPrint(MyPrint& mp, string text)
{mp(text);
}
void test03()
{MyPrint myprint;doPrint(myprint, "hello C++");
}int main()
{test01();test02();test03();system("pause");return 0;
}

输出结果:

20
hello world!
hello world!
hello world!
hello world!
MyPrint调用的次数:4
hello C++
请按任意键继续. . .

1.2谓词

1.2.1谓词对象

概念:

        返回bool类型的仿函数称为谓词

        如果operator()接受一个参数,那么叫做一元谓词

        如果operator()接受二个参数,那么叫做二元谓词

1.2.2一元谓词

#include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
//仿函数 返回值类型是bool数据类型  称为谓词
//如果operator()接受一个参数,那么叫做一元谓词
class GreaterFive
{
public:bool operator()(int val){return val > 5;}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}//查找容器中 是否有大于5的数字//GreaterFive() 匿名函数对象vector<int>::iterator it = find_if(v.begin(), v.end(), GreaterFive());if (it == v.end()){cout << "未找到" << endl;}else{cout << "找到了大于5的数字为:" << *it << endl;}
}int main()
{test01();system("pause");return 0;
}

输出结果:

找到了大于5的数字为:6
请按任意键继续. . .

1.2.3二元谓词

#include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
//仿函数 返回值类型是bool数据类型  称为谓词
//二元谓词
class MyCompare
{
public:bool operator()(int v1,int v2){return v1 > v2;}
};void test01()
{vector<int>v;v.push_back(30);v.push_back(20);v.push_back(50);v.push_back(10);v.push_back(40);sort(v.begin(), v.end());//默认升序for (vector<int>::iterator it = v.begin(); it != v.end(); it++){cout << *it << " ";}cout << endl;//使用函数对象,改变算法策略,变为降序sort(v.begin(), v.end(), MyCompare());cout << "---------------------------" << endl;for (vector<int>::iterator it = v.begin(); it != v.end(); it++){cout << *it << " ";}cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

10 20 30 40 50
---------------------------
50 40 30 20 10
请按任意键继续. . .

 1.3内建函数对象

1.3.1内建函数对象意义

概念:STL内建了一些函数对象

分类:
                算术仿函数
                关系仿函数
                逻辑仿函数

用法:这些仿函数所产生的对象,用法和一般函数完全相同。使用内建函数对象,需要引入头文件#include<functional>

1.3.2算术仿函数

功能描述:实现四则运算。其中negate是一元运算,其他都是二元运算

仿函数原型:

template<class T>T plus<T>       //加法仿函数
template<class T>T minus<T>      //减法仿函数
template<class T>T multiplies<T> //乘法仿函数
template<class T>T divides<T>    //除法仿函数
template<class T>T modulus<T>    //取模仿函数
template<class T>T negate<T>     //取反仿函数
#include <iostream>
using namespace std;
#include<functional>//内建函数对象头文件
//内建函数对象 算术仿函数
//template<class T>T plus<T>       //加法仿函数
//template<class T>T minus<T>      //减法仿函数
//template<class T>T multiplies<T> //乘法仿函数
//template<class T>T divides<T>    //除法仿函数
//template<class T>T modulus<T>    //取模仿函数
//template<class T>T negate<T>     //取反仿函数//negate 一元仿函数 取反仿函数
void test01()
{negate<int>n;cout << n(50) << endl;
}
//plus 二元仿函数 加法
void test02()
{plus<int>p;//默认传入同种数据类型,不能传入不同种数据类型cout << p(10, 20) << endl;
}
int main()
{test01();test02();system("pause");return 0;
}

输出结果:

-50
30
请按任意键继续. . .

1.3.3关系仿函数

功能描述:实现关系对比

仿函数原型:(最常用的是大于)

template<class T> bool equal_to<T>      //等于
template<class T> bool not_equal _to<T> //不等于
template<class T> bool greater<T>       //大于
template<class T> bool greater_equal<T> //大于等于
template<class T> bool less<T>          //小于
template<class T> bool less_equal<T>    //小于等于
#include <iostream>
using namespace std;
#include<functional>//内建函数对象头文件
#include<vector>
#include<algorithm>
//内建函数对象 关系仿函数
//template<class T> bool equal_to<T>      //等于
//template<class T> bool not_equal _to<T> //不等于
//template<class T> bool greater<T>       //大于
//template<class T> bool greater_equal<T> //大于等于
//template<class T> bool less<T>          //小于
//template<class T> bool less_equal<T>    //小于等于//大于 greater                
class MyCompare
{
public:bool operator()(int v1, int v2){return v1 > v2;}
};
void test01()
{vector<int>v;v.push_back(10);v.push_back(30);v.push_back(40);v.push_back(50);v.push_back(20);for (vector<int>::iterator it = v.begin(); it != v.end(); it++){cout << *it << " ";}cout << endl;//降序//sort(v.begin(), v.end(), MyCompare()); //自己重载仿函数sort(v.begin(), v.end(), greater<int>());//内建函数对象(仿函数)greater,效果一致for (vector<int>::iterator it = v.begin(); it != v.end(); it++){cout << *it << " ";}cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

10 30 40 50 20
50 40 30 20 10
请按任意键继续. . .

1.3.4逻辑仿函数

功能描述:实现逻辑运算

函数原型:

template<class T> bool logical_and<T> //逻辑与
template<class T> bool 1ogical_or<T>  //逻辑或
template<class T> bool logical_not<T> //逻辑非
#include <iostream>
using namespace std;
#include<functional>//内建函数对象头文件
#include<vector>
#include<algorithm>
//内建函数对象 关系仿函数
//template<class T> bool logical_and<T> //逻辑与
//template<class T> bool 1ogical_or<T>  //逻辑或
//template<class T> bool logical_not<T> //逻辑非//逻辑非 logical_not                
void test01()
{vector<bool>v;v.push_back(true);v.push_back(false);v.push_back(true);v.push_back(false);for (vector<bool>::iterator it = v.begin(); it != v.end(); it++){cout << *it << " ";}cout << endl;//利用逻辑非,将容器v搬运到容器v2中,并执行取反的操作vector<bool>v2;v2.resize(v.size());transform(v.begin(), v.end(), v2.begin(), logical_not<bool>());for (vector<bool>::iterator it = v2.begin(); it != v2.end(); it++){cout << *it << " ";}cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

1 0 1 0
0 1 0 1
请按任意键继续. . .

2、STL-常用算法

概述:

算法主要是由头文件<algorithm><functional><numeric>组成

<algorithm>是所有STL头文件中最大的一个,范围涉及到比较,交换,查找,遍历操作,复制,修改等

<numeric>体积很小,只包括几个在序列上面进行简单数学运算的模板函数

<functional>定义了一些模板类,用以声明函数对象

2.1 常用遍历算法

学习目标:掌握常用的遍历算法

算法简介:

for_each  //遍历容器
transform //搬运容器到另一个容器中

2.1.1 for_each

功能描述:实现遍历容器

函数原型:

for_each(iterator beg, iterator end, _func); 
// 遍历算法 遍历容器元素
// beg 开始迭代器
// end 结束迭代器
// _func函数或者函数对象
#include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
//常用遍历算法 for_each
//普通函数
void print01(int val)
{cout << val << " ";
}
//仿函数
class print02
{
public:void operator()(int val){cout << val << " ";}
};
void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}for_each(v.begin(), v.end(), print01);//普通函数放函数名cout << endl;for_each(v.begin(), v.end(), print02());//仿函数要放函数对象,加()cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
请按任意键继续. . .

总结:for_each在实际开发中是最常用遍历方法,需要熟练掌握 

2.1.2 transform

功能描述:搬运容器到另一个容器中

函数原型:

transform(iterator begl,iterator end1,iterator beg2,_func);
//beg1 源容器开始迭代器
//end1 源容器结束迭代器
//beg2 目标容器开始迭代器
//_func 函数或者函数对象
#include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
//常用遍历算法 transform
//仿函数
class Transform
{
public:int operator()(int v){return v + 10;}
};class MyPrint
{
public:void operator()(int v){cout << v << " ";}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}vector<int>vTarget;//目标容器vTarget.resize(v.size());//目标容器 需要提前开辟空间,否则搬运不成功transform(v.begin(), v.end(), vTarget.begin(), Transform());//可以在最后一个函数对搬运的数据进行运算或者改变 例如这次加10for_each(vTarget.begin(), vTarget.end(), MyPrint());//仿函数要放函数对象,加()cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

10 11 12 13 14 15 16 17 18 19
请按任意键继续. . .

2.2常用查找算法

学习目标:掌握常用的查找算法

算法简介:

find          //查找元素
find_if       //按条件查找元素
adjacent_find //查找相邻重复元素
binary_search //二分查找法
count         //统计元素个数
count_if      //按条件统计元素个数

2.2.1 find

功能描述:查找指定元素,找到返回指定元素的迭代器,找不到返回结束迭代器end()

函数原型:

find(iterator beg, iterator end, value);
// 按值查找元素,找到返回指定校置迭代器,找不到返回结束迭代器位置
// beg 开始迭代器
// end 结束迭代器
// value 查找的元素
#include <iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
//常用查找算法 find
//查找 内置数据类型
void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}vector<int>::iterator pos = find(v.begin(), v.end(), 5);if (pos == v.end()){cout << "没有找到!" << endl;}else{cout << "找到:" << *pos << endl;}
}class Person
{
public:Person(string name, int age){this->m_Name = name;this->m_Age = age;}//重载== 底层find知道如何对比Person数据类型bool operator==(const Person& p){if (this->m_Name == p.m_Name && this->m_Age == p.m_Age){return true;}else{return false;}}string m_Name;int m_Age;
};//查找 自定义数据类型
void test02()
{vector<Person>v;//创建数据Person p1("aaa", 10);Person p2("bbb", 20);Person p3("ccc", 30);Person p4("ddd", 40);Person pp("bbb", 20);//查找有无与此人相同的人//放入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);//查找vector<Person>::iterator pos = find(v.begin(), v.end(), pp);if (pos == v.end()){cout << "没有找到!" << endl;}else{cout << "找到此人 姓名:" << pos->m_Name << " 年龄:" << pos->m_Age << endl;}
}int main()
{test01();test02();system("pause");return 0;
}

输出结果:

找到:5
找到此人 姓名:bbb 年龄:20
请按任意键继续. . .

2.2.2 find_if

功能描述:按条件查找元素

函数原型:

find_if(iterator beg,iterator end,_Pred);
// 按值查找元素,找到返回指定位置选代器,找不到返回结束迭代器位置
// beg 开始迭代器
// end 结束迭代器
//_Pred 函数或者谓词(返回bool类型的仿函数)
#include <iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
//常用查找算法 find_if
//1、查找 内置数据类型
class GreaterFive
{
public:bool operator()(int val){return val > 5;}
};void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}vector<int>::iterator pos = find_if(v.begin(), v.end(), GreaterFive());if (pos == v.end()){cout << "没有找到!" << endl;}else{cout << "找到大于5的数字 为:" << *pos << endl;}
}class Person
{
public:Person(string name, int age){this->m_Name = name;this->m_Age = age;}string m_Name;int m_Age;
};class Greater20
{
public:bool operator()(Person& p){return p.m_Age > 20;}
};//2、查找 自定义数据类型
void test02()
{vector<Person>v;//创建数据Person p1("aaa", 10);Person p2("bbb", 20);Person p3("ccc", 30);Person p4("ddd", 40);Person pp("bbb", 20);//查找有无与此人相同的人//放入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);//查找年龄大于20的人vector<Person>::iterator pos = find_if(v.begin(), v.end(), Greater20());if (pos == v.end()){cout << "没有找到!" << endl;}else{cout << "找到此人 姓名:" << pos->m_Name << " 年龄:" << pos->m_Age << endl;}
}int main()
{test01();test02();system("pause");return 0;
}

输出结果:

找到大于5的数字 为:6
找到此人 姓名:ccc 年龄:30
请按任意键继续. . .

2.2.3 adjacent_find

功能描述:查找相邻重复元素

函数原型:

adjacent_find(iterator beg, iterator end);
// 查找相邻重复元素,返回相邻元素的第一个位置的选代器
// beg 开始迭代器
// end 结束迭代器
#include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
//常用查找算法 adjacent_find
void test01()
{vector<int>v;v.push_back(0);v.push_back(2);v.push_back(0);v.push_back(3);v.push_back(1);v.push_back(4);v.push_back(3);v.push_back(3);vector<int>::iterator pos = adjacent_find(v.begin(), v.end());if (pos == v.end()){cout << "没有找到相邻重复元素!" << endl;}else{cout << "找到相邻重复元素:" << *pos << endl;}
}int main()
{test01();system("pause");return 0;
}

输出结果:

找到相邻重复元素:3
请按任意键继续. . .

2.2.4 binary_search

功能描述:查找指定元素是否存在  注意: 在无序序列中不可用

函数原型:

bool binary_search(iterator beg, iterator end, value);
// 查找指定的元素,查到返回true 否则false
// 注意: 在无序序列中不可用
// beg 开始迭代器
// end 结束迭代器
// value 查找的元素n
#include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
//常用查找算法 binary_search
void test01()
{vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}//查找容器中是否有9 元素//注意: 在无序序列中不可用//如果是无序序列,结果未知//必须要有序bool ret = binary_search(v.begin(), v.end(), 9);if (ret){cout << "找到了元素!" << endl;}else{cout << "未找到!" << endl;}
}int main()
{test01();system("pause");return 0;
}

输出结果:

找到了元素!
请按任意键继续. . .

2.2.5 count

功能描述:统计元素个数

注意:统计自定义数据类型时,需要配合重载operator==

函数原型:

count(iterator beg, iterator end, value);
// 统计元素出现次数
// beg 开始迭代器
// end 结束迭代器
// value 统计的元素
#include <iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
//常用查找算法 count
//1、统计内置数据类型
void test01()
{vector<int>v;v.push_back(10);v.push_back(40);v.push_back(30);v.push_back(40);v.push_back(20);v.push_back(40);int num = count(v.begin(), v.end(), 40);cout << "40元素个数为:" << num << endl;
}
//2、统计自定义数据类型
class Person
{
public:Person(string name, int age){this->m_Name = name;this->m_Age = age;}//需要加const,防止用户修改Person//否则会报错bool operator==(const Person& p){if (this->m_Age == p.m_Age){return true;}else{return false;}}string m_Name;int m_Age;
};void test02()
{vector<Person>v;Person p1("刘备", 35);Person p2("关羽", 35);Person p3("张飞", 35);Person p4("赵云", 30);Person p5("曹操", 40);//将人员插入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);v.push_back(p5);Person p("诸葛亮", 35);int num = count(v.begin(), v.end(), p);cout << "与诸葛亮同岁数的人员个数为:" << num << endl;
}int main()
{test01();test02();system("pause");return 0;
}

输出结果:

40元素个数为:3
与诸葛亮同岁数的人员个数为:3
请按任意键继续. . .

2.2.6 count_if

功能描述:按条件统计元素个数

函数原型:

count_if(iterator beg, iterator end, _pred);
// 按条件统计元素出现次数
// beg 开始迭代器
// end 结束迭代器
// _Pred 谓词
#include <iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
//常用查找算法 count_if
//1、统计内置数据类型
class Greater20
{
public:bool operator()(int val){return val > 20;}
};
void test01()
{vector<int>v;v.push_back(10);v.push_back(40);v.push_back(30);v.push_back(20);v.push_back(40);v.push_back(20);int num = count_if(v.begin(), v.end(), Greater20());cout << "大于20的元素个数为:" << num << endl;
}
//2、统计自定义数据类型
class Person
{
public:Person(string name, int age){this->m_Name = name;this->m_Age = age;}//需要加const,防止用户修改Person//否则会报错bool operator==(const Person& p){if (this->m_Age == p.m_Age){return true;}else{return false;}}string m_Name;int m_Age;
};class AgeGreater20
{
public:bool operator()(const Person& p){return p.m_Age > 20;}
};void test02()
{vector<Person>v;Person p1("刘备", 35);Person p2("关羽", 35);Person p3("张飞", 35);Person p4("赵云", 40);Person p5("曹操", 20);//将人员插入到容器中v.push_back(p1);v.push_back(p2);v.push_back(p3);v.push_back(p4);v.push_back(p5);int num = count_if(v.begin(), v.end(), AgeGreater20());cout << "大于20岁的人员个数为:" << num << endl;
}int main()
{test01();test02();system("pause");return 0;
}

输出结果:

大于20的元素个数为:3
大于20岁的人员个数为:4
请按任意键继续. . .

相关文章:

C++提高笔记(六)---STL函数对象、STL常用算法(遍历、查找)

1、STL-函数对象 1.1函数对象 1.1.1函数对象概念 概念&#xff1a; 重载函数调用操作符的类&#xff0c;其对象常称为函数对象 函数对象使用重载的()时&#xff0c;行为类似函数调用&#xff0c;也叫仿函数 本质&#xff1a;函数对象(仿函数)是一个类&#xff0c;不是一个…...

【每日一问】手机如何开启USB调试?

一、背景 当电脑跟手机之间需要进行交互的时候&#xff0c;可以考虑使用usb进行连接。那么手机如何开启USB调试呢&#xff1f; 二、操作步骤&#xff1a; 思路&#xff1a; 步骤1&#xff1a;手机开启开发者模式 步骤2&#xff1a;在开发者模式中&#xff0c;开启“USB调试”…...

Java映射知识点(含面试大厂题含源码)

在Java中&#xff0c;映射&#xff08;Map&#xff09;是一个存储键值对的数据结构&#xff0c;其中每个键映射到一个值。Java提供了几种实现Map接口的类&#xff0c;以满足不同的需求。了解映射的知识点可以帮助你在处理需要键值关联的数据时更加高效。 核心知识点 Map接口&a…...

拆解Spring boot:Springboot为什么如此丝滑而简单?源码剖析解读自动装配

&#x1f389;&#x1f389;欢迎光临&#xff0c;终于等到你啦&#x1f389;&#x1f389; &#x1f3c5;我是苏泽&#xff0c;一位对技术充满热情的探索者和分享者。&#x1f680;&#x1f680; &#x1f31f;持续更新的专栏《Spring 狂野之旅&#xff1a;从入门到入魔》 &a…...

中国银行信息系统应用架构发展历程

概述&#xff1a; 从 20 世纪 80 年代开始至今&#xff0c;我国银行业信息化历程已 有四十年历史。虽然相对于发达国家来讲&#xff0c;我国银行业务信 息化起步较晚&#xff0c;但发展速度很快&#xff0c; 目前我国一些大型商业银行的信息化程度已经处于全球领先水平。 “银行…...

掌握Go语言:探索Go语言指针,解锁高效内存操作与动态数据结构的奥秘(19)

指针是一个变量&#xff0c;它存储了另一个变量的地址。在Go语言中&#xff0c;指针提供了直接访问内存地址的能力&#xff0c;允许程序直接操作内存&#xff0c;这在某些场景下非常有用。 Go语言指针的详细使用方法 声明指针 可以使用*符号来声明指针变量&#xff0c;例如&…...

大数据面试题 —— Zookeeper

目录 ZooKeeper 的定义ZooKeeper 的特点ZooKeeper 的应用场景你觉得Zookeeper比较重要的功能ZooKeeper 的选举机制 ***zookeeper主节点故障&#xff0c;如何重新选举&#xff1f;ZooKeeper 的监听原理 ***zookeeper集群的节点数为什么建议奇数台 ***ZooKeeper 的部署方式有哪几…...

【安全类书籍-6】僵尸网络:网络程序杀手

目录 内容 用处 下载链接 内容 这本书着重探讨以下几个主题: 1. 僵尸网络基础:介绍僵尸网络的基本构成、运作机制以及在全球网络空间中的影响和威胁程度。 2. 僵尸网络技术剖析:详细分析僵尸网络的组件,如命令控制中心(C&C)、恶意软件传播途径、感染节点的招募和…...

文件的创建与删除

文件的创建 使用File类创建一个文件对象&#xff0c;例如&#xff1a;File filenew File("c:\\myletter" , "letter.txt"); public boolean createNewFile();/*如果c:\myletter目录中没 有名字为letter.txt文件&#xff0c;文件对象file调用createNewFil…...

图论题目集一(代码 注解)

目录 题目一&#xff1a; 题目二&#xff1a; 题目三&#xff1a; 题目四&#xff1a; 题目五&#xff1a; 题目六&#xff1a; 题目七&#xff1a; 题目一&#xff1a; #include<iostream> #include<queue> #include<cstring> using namespace st…...

解释MVC和MVVM架构模式

一、解释MVC和MVVM架构模式 MVC和MVVM都是常见的前端架构模式&#xff0c;用于抽象分离并解决特定问题。这两种模式在结构上具有一定的相似性&#xff0c;但在细节和数据处理方式上存在一些差异。 MVC&#xff0c;即Model-View-Controller&#xff0c;是一种用于应用程序分层…...

OLLAMA:如何像云端一样运行本地大语言模型

简介&#xff1a;揭开 OLLAMA 本地大语言模型的神秘面纱 您是否曾发现自己被云端语言模型的网络所缠绕&#xff0c;渴望获得更本地化、更具成本效益的解决方案&#xff1f;那么&#xff0c;您的探索到此结束。欢迎来到 OLLAMA 的世界&#xff0c;这个平台将彻底改变我们与大型…...

React全家桶及原理解析-lesson4-Redux

lesson4-react全家桶及原理解析.mov React全家桶及原理解析 React全家桶及原理解析 课堂⽬标资源起步Reducer 什么是reducer什么是reduceRedux 上⼿ 安装reduxredux上⼿检查点react-redux 异步代码抽取Redux拓展 redux原理 核⼼实现中间件实现redux-thunk原理react-redux原理 实…...

电商api数据接口技术开发来赞达lazada通过商品ID抓取商品详情信息item_get请求key接入演示

要获取Lazada的商品详情&#xff0c;你需要使用item_get请求。首先&#xff0c;你需要注册一个开发者账号并获取API密钥&#xff08;App Key和App Secret&#xff09;。然后&#xff0c;你可以使用以下Python代码示例来获取商品详情&#xff1a; # coding:utf-8 ""&…...

零基础入门多媒体音频(2)-音频焦点2

说实话&#xff0c;android的代码是越来越难以阅读。业务函数里面狗皮膏药似的补丁与日俱增。继上篇简要介绍音频焦点的文章&#xff0c;这篇文章的主要内容是分析audiofocus的实现。看了一下午的相关代码都没找到做audiofocus策略的核心逻辑。目前能看懂的大概包含下面两个逻辑…...

Spark杂谈

文章目录 什么是Spark对比HadoopSpark应用场景Spark数据处理流程什么是RDDSpark架构相关进程入门案例&#xff1a;统计单词数量Spark开启historyServer 什么是Spark Spark是一个用于大规模数据处理的统一计算引擎Spark一个重要的特性就是基于内存计算&#xff0c;从而它的速度…...

【PyTorch】进阶学习:一文详细介绍 torch.save() 的应用场景、实战代码示例

【PyTorch】进阶学习&#xff1a;一文详细介绍 torch.save() 的应用场景、实战代码示例 &#x1f308; 个人主页&#xff1a;高斯小哥 &#x1f525; 高质量专栏&#xff1a;Matplotlib之旅&#xff1a;零基础精通数据可视化、Python基础【高质量合集】、PyTorch零基础入门教程…...

私域流量运营的关键要素和基本步骤

解锁增长的四大关键&#xff1a; 关键要素一&#xff1a;精准营销 精准营销是私域流量运营的核心所在。通过精细化运营和个性化服务&#xff0c;企业可以将普通用户转化为忠实粉丝&#xff0c;提高用户的粘性和转化率。采用数据驱动的精准营销策略&#xff0c;深度挖掘用户需求…...

k8s部署hadoop

&#xff08;作者&#xff1a;陈玓玏&#xff09; 配置和模板参考helm仓库&#xff1a;https://artifacthub.io/packages/helm/apache-hadoop-helm/hadoop 先通过以下命令生成yaml文件&#xff1a; helm template hadoop pfisterer-hadoop/hadoop > hadoop.yaml用kube…...

deepspeed分布式训练在pytorch 扩展(PyTorch extensions)卡住

错误展示&#xff1a; Using /root/.cache/torch_extensions/py310_cu121 as PyTorch extensions root...
 Using /root/.cache/torch_extensions/py310_cu121 as PyTorch extensions root...
 错误表现&#xff1a; 出现在多卡训练过程的pytorch 扩展&#xff0c;deepspee…...

Rust 的 HashMap

在 Rust 中&#xff0c;HashMap 是一个从键&#xff08;key&#xff09;映射到值&#xff08;value&#xff09;的数据结构。它允许你以 O(1) 的平均时间复杂度存储、检索和删除键值对。HashMap 实现了 std::collections::HashMap 结构体&#xff0c;通常通过 use std::collect…...

exporter方式监控达梦数据库

蓝鲸监控 随着国产化和信创的深入&#xff0c;开始普遍使用国产化数据库–如达梦数据库&#xff0c;蓝鲸平台默认没有对其进行监控&#xff0c;但是平台了提供监控告警的能力。比如脚本采集&#xff0c;脚本的是一种灵活和快速的监控采集方式&#xff0c;不同层的监控对象都可…...

供应链安全之被忽略的软件质量管理平台安全

背景 随着我国信息化进程加速&#xff0c;网络安全问题更加凸显。关键信息基础设施和企业单位在满足等保合规的基础上&#xff0c;如何提升网络安全防御能力&#xff0c;降低安全事件发生概率&#xff1f;默安玄甲实验室针对SonarQube供应链安全事件进行分析&#xff0c;强调供…...

python入门(二)

python的安装很方便&#xff0c;我们这里就不再进行讲解&#xff0c;大家可以自己去搜索视频。下面分享一下Python的入门知识点。 执行命令的方式 在安装好python后&#xff0c;有两种方式可以执行命令&#xff1a; 命令行程序文件&#xff0c;后缀名为.py 对于命令行&…...

Mysql,MongoDB,Redis的横纵向对比

一,什么是Mysql Mysql是一款安全,可以跨平台,高效率的数据库系统,运行速度高,安全性能高,支持面向对象,安全性高,并且成本比较低,支持各种开发语言,数据库的存储容量大,有许多的内置函数。 二,什么是MongoDB MongoDB是基于分布式文件存储的数据库,是一个介于关…...

css3 实现html样式蛇形布局

文章目录 1. 实现效果2. 实现代码 1. 实现效果 2. 实现代码 <template><div class"body"><div class"title">CSS3实现蛇形布局</div><div class"list"><div class"item" v-for"(item, index) …...

基于消失点的相机自标定

基于消失点的相机自标定 附赠最强自动驾驶学习资料&#xff1a;直达链接 相机是通过透视投影变换来将3D场景转换为2D图像。在射影变换中&#xff0c;平行线相交于一点称之为消失点。本文详细介绍了两种利用消失点特性的标定方法。目的是为根据实际应用和初始条件选择合适的标…...

Python:filter过滤器

filter() 是 Python 中的一个内置函数&#xff0c;用于过滤序列&#xff0c;过滤掉不符合条件的元素&#xff0c;返回由符合条件元素组成的新列表。该函数接收两个参数&#xff0c;一个是函数&#xff0c;一个是序列&#xff0c;序列的每个元素作为参数传递给函数进行判定&…...

Python函数学习

Python函数学习 1.函数定义 在函数定义阶段只检查函数的语法问题 2.实参形参 ​​​​总结&#xff1a; &#xff08;1&#xff09;位置参数就是经常用的按照位置顺序给出实参的值&#xff1b; &#xff08;2&#xff09;关键字实参形式&#xff1a;key123&#xff1b;放在…...

IDEA中的Project工程、Module模块的概念及创建导入

1、IDEA中的层级关系&#xff1a; project(工程) - module(模块) - package(包) - class(类)/接口具体的&#xff1a; 一个project中可以创建多个module一个module中可以创建多个package一个package中可以创建多个class/接口2、Project和Module的概念&#xff1a; 在 IntelliJ …...

网站商城设计/响应式网站 乐云seo品牌

往期 精 选&#xff1a;...

用python做 网站论坛/整站优化包年

finalize 它是 Object 中的一个方法&#xff0c;如果子类重写它&#xff0c;垃圾回收时此方法会被调用&#xff0c;可以在其中进行资源释放和清理工作 将资源释放和清理放在 finalize 方法中非常不好&#xff0c;非常影响性能&#xff0c;严重时甚至会引起 OOM&#xff0c;从 …...

郑州微信公众号外包/广州seo托管

题目要求&#xff1a; 本题要求编写程序&#xff0c;输入N个学生的MOOC成绩&#xff0c;统计优秀、合格证书的数量&#xff0c;以及没有获得证书的数量。学生修读程序设计MOOC&#xff0c;85分及以上获得优秀证书&#xff0c;不到85分但是60分及以上获得合格证书&#xff0c;不…...

好看的模板网站建设/头条今日头条新闻头条

一、HSTS协议 这里我们要借助一个新的安全协议&#xff1a;HSTSHSTS&#xff08;HTTP Strict Transport Security&#xff09;国际互联网工程组织IETE正在推行一种新的Web安全协议&#xff0c;作用是强制客户端&#xff08;如浏览器&#xff09;使用HTTPS与服务器创建连接。主要…...

wordpress找回密码链接/分析网站推广和优化的原因

创建、删除 数据库 数据表 创建新的数据库 CREATE DATABASE 数据库名; 例如&#xff1a;CREATE DATABASE SCHOOL; 在数据库中新建表 CREATE TABLE 表名 (字段1 数据类型,字段2 数据类型[,…][,PRIMARY KEY (主键名)]); #主键一般选择能代表唯一性的字段不允许取空值&#…...

怎么做中英文的网站/直链平台

#目录 文章目录1. Redis安装约定2. 下载Redis安装包3. 解压并进入安装包中查看重要的文件及目录4. 正式安装redis5. 安装完成后查看安装目录6. 配置环境变量7. 拷贝安装包目录下的配置文件到安装目录的conf目录下8. 启动redis服务9. 再次启动redis服务10. 检查redis服务是否启动…...