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

string的模拟实现

string的模拟实现

    • msvc和g++下的string内存比较
    • 成员变量
    • 构造函数与析构函数
    • 拷贝构造函数
    • 赋值拷贝
    • c_str、size和capacity函数以及重载[]、clear、expand_capacity
    • 迭代器与遍历
    • reserve
    • push_back、append、+=
    • insert
    • 字符串比较运算符
    • erase
    • <<流提取 >>流插入
    • resize
    • find
    • substr
    • 源码地址


msvc和g++下的string内存比较

int main()
{std::string str1("HelloWorld");std::string str2("HelloWorldHelloWorld");cout << sizeof(str1) << " " << sizeof(str2) << endl;return 0;
}

在windows下使用vs2022 x64运行输出都为40字节:调试上面程序,在自动窗口中观察str1和str2的原始视图:
在这里插入图片描述

发现buf是包含16个字符的数组,里面存放了字符串,ptr为空,size和res分别为字符个数和容量。

而查看str2的字符串视图:发现buf数组为随机值,ptr指向实际的字符串,size和res分别为字符个数和容量。

在这里插入图片描述

MSVC编译器使用的string类内存模型可大概表示如下:

class string
{
private:char _buf[16];char* _ptr;size_t _size;size_t _capacity;
};

在64位下是40字节。


在g++11.4.0版本下运行结果为32字节。可以验证g++和vs2022的msvc都没有使用写拷贝:

int main() {string str1("hello world");string str2(str1);cout << (void *) str1.c_str() << endl; // 0xe8ce3ff7e0cout << (void *) str2.c_str() << endl; // 0xe8ce3ff7c0return 0;
}

现在我们来探索一下g++下的string内存结构:

int main() {std::string s1 = "HelloWorld";std::string s2 = "HelloWorldHelloWorld";std::string s3 = "HelloWorldHelloWorldHelloWorld";cout << (void *) &s1 << " " << (void *) s1.c_str() << endl;cout << (void *) &s2 << " " << (void *) s2.c_str() << endl;cout << (void *) &s3 << " " << (void *) s3.c_str() << endl;return 0;
}
# 观察到s1的内存
0x00000000005ffe10   20 fe 5f 00   00 00 00 00   │  ·_····· │ 
0x00000000005ffe18   0a 00 00 00   00 00 00 00   │ ········ │
0x00000000005ffe20   48 65 6c 6c   6f 57 6f 72   │ HelloWor │
0x00000000005ffe28   6c 64 00 00   01 00 00 00   │ ld······ │
---------------------------------------------------------------------
# 观察到s2的内存
0x00000000005ffdf0   40 47 70 00   00 00 00 00   │ @Gp····· │
0x00000000005ffdf8   14 00 00 00   00 00 00 00   │ ········ │
0x00000000005ffe00   14 00 00 00   00 00 00 00   │ ········ │
0x00000000005ffe08   45 15 8c be   f7 7f 00 00   │ E······· │# s2指向的字符串
0x0000000000704740   48 65 6c 6c   6f 57 6f 72   │ HelloWor │
0x0000000000704748   6c 64 48 65   6c 6c 6f 57   │ ldHelloW │
0x0000000000704750   6f 72 6c 64   00 ab ab ab   │ orld···· │ 
---------------------------------------------------------------------    
# 观察到s3的内存
0x00000000005ffdd0   90 47 70 00   00 00 00 00   │ ·Gp····· │ # 指向字符数组
0x00000000005ffdd8   1e 00 00 00   00 00 00 00   │ ········ │ # size
0x00000000005ffde0   1e 00 00 00   00 00 00 00   │ ········ │ # capacity
0x00000000005ffdd8   00 00 00 00   00 00 00 00   │ ········ │# s3指向的字符串
0x0000000000704790   48 65 6c 6c   6f 57 6f 72   │ HelloWor │
0x0000000000704798   6c 64 48 65   6c 6c 6f 57   │ ldHelloW │
0x00000000007047a0   6f 72 6c 64   48 65 6c 6c   │ orldHell │
0x00000000007047a8   6f 57 6f 72   6c 64 00 ab   │ oWorld·· │

观察上面3个string对象我们知道,第一个成员是char*的_str,指向保存的字符串地址。第二个成员是size。如果是小于等于15个字符,则后面16个字节保存短字符串。如果是大于15个字符的字符串,则第三个成员保存capacity容量,第四个成员则没有意义。

// 短字符串
class string {
private:char* _str;size_t _size;char _buf[16];
};// 长字符串
class string {
private:char* _str;size_t _size;size_t _capacity;size_t _reserve;
};

验证猜想:

int main() {std::string s1 = "HelloWorldHello";std::string s2 = "HelloWorldHelloWorld";std::string s3 = "HelloWorldHelloWorldHelloWorld";cout << (void *) &s1 << " " << (void *) s1.c_str() << " " << s1.size() << " " << s1.capacity() << endl;cout << (void *) &s2 << " " << (void *) s2.c_str() << " " << s2.size() << " " << s2.capacity() << endl;cout << (void *) &s3 << " " << (void *) s3.c_str() << " " << s3.size() << " " << s3.capacity() << endl;s1.push_back('*'); // 插入数据扩容cout << (void *) &s1 << " " << (void *) s1.c_str() << " " << s1.size() << " " << s1.capacity() << endl;s3.push_back('*'); // 插入数据扩容cout << (void *) &s3 << " " << (void *) s3.c_str() << " " << s3.size() << " " << s3.capacity() << endl;return 0;
}
/*
0xdd031ffde0 0xdd031ffdf0 15 15    # 扩容前s1
0xdd031ffdc0 0x2a486af25b0 20 20   # s2
0xdd031ffda0 0x2a486af6820 30 30   # s3
0xdd031ffde0 0x2a486af7860 16 30   # 扩容后s1
0xdd031ffda0 0x2a486af7890 31 60   # 扩容后s3
*/

成员变量

为了简单模拟字符串,我们不像g++和msvc一样保留对短字符串的处理,我们定义如下几个变量:

namespace my_std
{class string{private:char* _str; // 字符串数组size_t _size;size_t _capacity;static const size_t npos;};const size_t string::npos = -1;
}
// size:当前有效字符的个数
// capacity:最大能容纳的有效字符的个数,不包括\0

在自己的命名空间 my_std 中实现,防止与std冲突。

下面我们将模拟g++下的string,可以对照g++的string输出作为参考。

构造函数与析构函数

std标准库中string构造函数的使用:

int main() {std::string s1 = "HelloWorldHello";std::string s2 = "HelloWorldHelloWorld";std::string s3 = "HelloWorldHelloWorldHelloWorld";cout << (void *) &s1 << " " << (void *) s1.c_str() << " " << s1.size() << " " << s1.capacity() << endl;cout << (void *) &s2 << " " << (void *) s2.c_str() << " " << s2.size() << " " << s2.capacity() << endl;cout << (void *) &s3 << " " << (void *) s3.c_str() << " " << s3.size() << " " << s3.capacity() << endl;return 0;
}
/*
0x84b4fff660 0x84b4fff670 15 15
0x84b4fff640 0x23a3caa25b0 20 20
0x84b4fff620 0x23a3caa6820 30 30
*/

我们模拟实现如下:这里的默认参数旨在一个string空对象的正确打印。

string(const char* str = ""): _size(strlen(str))
{_capacity = (_size <= 15) ? 15 : _size;_str = new char[_capacity + 1];strcpy(_str, str);
}

如果是短字符串,我们将容量设置为15。如果是长字符串,容量设置为实际长度。

这里需要注意strcpy会拷贝 '\0'


下面是析构函数实现:因为构造函数中我们保证了容量至少是15,并且下面的实现resize中即使缩容也不会影响capacity实际容量,因此 _str不会为空。可以不加 _str 为空的判断。

~string()
{delete[] _str;_str = nullptr;_size = _capacity = 0;
}

拷贝构造函数

先看标准库中string的使用:

void test() {std::string str = "helloworldhelloworld";cout << str.size() << " " << str.capacity() << " " << (void *) str.c_str() << endl; // 20 20 0x18ff84f25b0str.push_back('#');cout << str.size() << " " << str.capacity() << " " << (void *) str.c_str() << endl; // 21 40 0x18ff84f7830std::string str1 = str;cout << str1.size() << " " << str1.capacity() << " " << (void *) str1.c_str() << endl; // 21 21 0x18ff84f25b0}int main() {test();return 0;
}

可以观察到拷贝构造的str1的size和capacity都等于str的size,因此可以实现如下:

string(const string& s)
{// apply the new space_size = s._size;_capacity = s._size;_str = new char[_capacity + 1];// copy strstrcpy(_str, s.c_str());
}

赋值拷贝

先看g++下的赋值拷贝:

void test() {string str = "helloworldhelloworld";cout << "str:" << str.size() << " " << str.capacity() << " " << (void *) str.c_str() << endl;str.push_back('#');cout << "str插入#:" << str.size() << " " << str.capacity() << " " << (void *) str.c_str() << endl;string str1;cout << "str1扩容前:" << str1.size() << " " << str1.capacity() << " " << (void *) str1.c_str() << endl;string str2 = "Hello";cout << str2.size() << " " << str2.capacity() << " " << (void *) str2.c_str() << endl;// 短字符串 原地复制str1 = str2;cout << "str1短字符串原地复制:" << str1.size() << " " << str1.capacity() << " " << (void *) str1.c_str() << endl;// 长字符串 两倍扩容str1 = str;cout << "str1长字符串两倍扩容:" << str1.size() << " " << str1.capacity() << " " << (void *) str1.c_str() << endl;str += "helloworldhelloworld";cout << str.size() << " " << str.capacity() << " " << (void *) str.c_str() << endl;// 长字符串 两倍扩容不够 扩容到s.size()string str3;cout << "str3扩容前:" << str3.size() << " " << str3.capacity() << " " << (void *) str3.c_str() << endl;str3 = str;cout << "str3扩容后:" << str3.size() << " " << str3.capacity() << " " << (void *) str3.c_str() << endl;}int main() {test();return 0;
}
/*
str:20 20 0x17f061725b0
str插入#:21 40 0x17f06177830
str1扩容前:0 15 0x4dc55ffbc0
5 15 0x4dc55ffba0
str1短字符串原地复制:5 15 0x4dc55ffbc0
str1长字符串两倍扩容:21 30 0x17f061725b0
41 80 0x17f06177870
str3扩容前:0 15 0x4dc55ffb80
str3扩容后:41 41 0x17f06177830
*/

在等号赋值的过程中,如果赋值的字符串较短,则在原来的内存空间中直接复制。否则发生扩容,如果两倍扩容不够,则扩容到s._size。

string& operator=(const string& s)
{if (&s != this){if (s._size > _capacity){// 两倍扩容不够,则扩容到s._size_capacity = (s._size > 2 * _capacity) ? s._size : 2 * _capacity;delete[] _str;_str = new char[_capacity + 1];}strcpy(_str, s._str);_size = s._size;}return *this;
}

下面写了reserve函数之后可以修改为:代码上更简洁,但是多了一次拷贝。

string& operator=(const string& s)
{if (&s != this){reserve(s._size);strcpy(_str, s._str);_size = s._size;}return *this;
}

c_str、size和capacity函数以及重载[]、clear、expand_capacity

const char* c_str() const
{return _str;
}size_t size() const
{return _size;
}size_t capacity() const
{return _capacity;
}char& operator[](size_t pos)
{assert(pos < _size);return _str[pos];
}const char& operator[](size_t pos) const
{assert(pos < _size);return _str[pos];
}

这里还专门针对const string对象写了重载[]的const成员函数。


void expand_capacity(std::string &str) {size_t old_capacity = str.capacity();cout << "init capacity: " << old_capacity << endl;for (int i = 0; i < 100; ++i) {str.append("h");//str.push_back('h');if (old_capacity != str.capacity()) {old_capacity = str.capacity();cout << "expand capacity: " << old_capacity << endl;}}
}int main() {string str;expand_capacity(str);cout << str.size() << " " << str.capacity() << endl;str.clear();cout << str.size() << " " << str.capacity() << endl;return 0;
}
/*
init capacity: 15
expand capacity: 30
expand capacity: 60
expand capacity: 120
100 120
0 120
*/

clear函数将size置0,容量保留:

void clear()
{_str[0] = '\0';_size = 0;
}

迭代器与遍历

class string
{
public:typedef char* iterator;iterator begin(){return _str;}iterator end(){return _str + _size;}
}

测试:

int main()
{// 遍历测试string str1("hello world");cout << str1.c_str() << endl;for (size_t i = 0; i < str1.size(); ++i){cout << str1[i] << " ";}cout << endl;string::iterator it = str1.begin();while (it != str1.end()){cout << *it << " ";++it;}cout << endl;for (auto ch : str1){cout << ch << " ";}cout << endl;return 0;
}

reserve

void test() {string s = "hello";cout << s.size() << " " << s.capacity() << " " << s << endl;s.reserve(5);cout << "(05)" << s.size() << " " << s.capacity() << " " << s << endl;s.reserve(18);cout << "(18)" <<  s.size() << " " << s.capacity() << " " << s << endl;s.reserve(61);cout << "(61)" <<  s.size() << " " << s.capacity() << " " << s << endl;
}int main() {test();return 0;
}
/*
5 15 hello
(05)5 15 hello
(18)5 30 hello
(61)5 61 hello
*/

标准库中的reserve函数的使用,reserve参数如果比capacity小,则没有变化。reserve参数比capacity大,发生扩容,如果两倍扩容不够,则扩容到输入的参数。

void reserve(size_t n)
{if (n > _capacity){// 两倍扩容不够,则扩容到n_capacity = (n > 2 * _capacity) ? n : 2 * _capacity;char* tmp = new char[_capacity + 1];strcpy(tmp, _str);delete[] _str;_str = tmp;}
}

push_back、append、+=

void push_back(char ch)
{/*if (_size == _capacity){reserve(_capacity * 2);}*/reserve(_size + 1);_str[_size++] = ch;_str[_size] = '\0';
}void append(const char* str)
{size_t len = strlen(str);reserve(_size + len);strcpy(_str + _size, str);_size += len;
}string& operator+=(const char* str)
{append(str);return *this;
}string& operator+=(char ch)
{push_back(ch);return *this;
}

值得说的是,有了上面的reserve,我们在扩容时,代码上就可以更简洁,不用进行 _size == _capacity 的判断:

void push_back(char ch)
{/*if (_size == _capacity){reserve(_capacity * 2);}*/reserve(_size + 1);_str[_size++] = ch;_str[_size] = '\0';
}

insert

要从 '\0' 开始向后移动,使用时注意while循环对size_t类型的判断,避免导致死循环:

void insert(size_t pos, char ch)
{assert(pos <= _size);reserve(_size + 1);/*size_t end = _size; // from '\0' startwhile (end >= pos)  // when pos=0, while loop will not exit{_str[end + 1] = _str[end];--end;}*/size_t end = _size + 1; // from '\0' next pos startwhile (end > pos){_str[end] = _str[end - 1];--end;}_str[pos] = ch;_size++;
}

下面是插入字符串str:

void insert(size_t pos, const char* str)
{assert(pos <= _size);size_t len = strlen(str);reserve(_size + len);// 向后挪动数据size_t end = _size + 1; // from '\0' next pos startwhile (end > pos){_str[end - 1 + len] = _str[end - 1];--end;}// 拷贝数据/*for (int i = 0; i < len; ++i){_str[i + pos] = str[i];}*/strncpy(_str + pos, str, len);_size += len;
}

这里使用 strncpy 指定拷贝的字节数。

字符串比较运算符

bool operator<(const string& s) const
{return strcmp(_str, s._str) < 0;
}bool operator==(const string& s) const
{return strcmp(_str, s._str) == 0;
}bool operator<=(const string& s) const
{return *this < s || *this == s;
}bool operator>(const string& s) const
{return !(*this <= s);
}bool operator>=(const string& s) const
{return !(*this < s);
}bool operator!=(const string& s) const
{return !(*this == s);
}

erase

void erase(size_t pos, size_t len = npos)
{assert(pos < _size);if (len == npos || pos + len >= _size){// 从pos删除到结尾_str[pos] = '\0';_size = pos;}else{// 从pos删除len长度个strcpy(_str + pos, _str + pos + len);_size -= len;}
}

验证:

int main()
{string str1("helloworld");cout << str1 << " " << str1.size() << " " << str1.capacity() << endl;str1.erase(6);cout << str1 << " " << str1.size() << " " << str1.capacity() << endl;str1.erase(0);cout << str1 << " " << str1.size() << " " << str1.capacity() << endl;return 0;
}/*
helloworld 10 15
hellow 6 150 15
*/

<<流提取 >>流插入

将<<和 >> 重载为全局函数,放在my_std命名空间中:

std::ostream& operator <<(std::ostream& out, const string& s)
{out << s.c_str();return out;
}

使用 istream::get() 方法,每次读取一个字符进行插入。

std::istream& operator>>(std::istream& in, string& s)
{s.clear();char ch;// in >> ch;ch = in.get(); // istream::get()while (ch != ' ' && ch != '\n'){s += ch;ch = in.get();}return in;
}

每次字符串执行+= s += ch; 效率太低,我们加入buf,提高插入的效率:

std::istream& operator>>(std::istream& in, string& s)
{s.clear();char buf[128] = { '\0' };size_t i = 0;char ch;// in >> ch;ch = in.get(); // istream::get()while (ch != ' ' && ch != '\n'){//s += ch;if (i == 127){s += buf;i = 0;}buf[i] = ch;i++;ch = in.get();}if (i >= 0){buf[i] = '\0';s += buf;}return in;
}

resize

cplusplus的resize

void resize (size_t n);
void resize (size_t n, char c);
int main()
{//test_main();string s1("hello world");cout << s1 << " " << s1.size() << " " << s1.capacity() << endl;s1.resize(5);cout << s1 << " " << s1.size() << " " << s1.capacity() << endl;s1.resize(50, 'x');cout << s1 << " " << s1.size() << " " << s1.capacity() << endl;return 0;
}
/*
hello world 11 15
hello 5 15
helloxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 50 50
*/

假设有字符串 str = "hello world" 的size为11,capacity为10。

针对以下三种参数调整空间:

1.当n=5时,也就是n<=size,可以直接令 str[5] = '\0',size变为5,容量不变。

2.当n=15时,也就是n>size,需要插入数据,直接调用reserve扩容为n个空间,然后将剩下的插入指定字符c。

我们自己实现的resize:

void resize(size_t n, char ch = '\0')
{if (n <= _size){_str[n] = '\0';_size = n;}else{reserve(n);while (_size < n){_str[_size] = ch;++_size;}_str[_size] = '\0';}
}

find

find返回指定字符或者字符串从pos开始的下标:

size_t find(char ch, size_t pos = 0)
{for (size_t i = pos; i < _size; i++){if (_str[i] == ch){return i;}}return npos;
}size_t find(const char* sub, size_t pos = 0)
{const char* p = strstr(_str + pos, sub);if (p){return p - _str;}else{return npos;}
}

substr

cplusplus.com/reference/string/string/substr/

string substr (size_t pos = 0, size_t len = npos) const;

实现如下:

string substr(size_t pos, size_t len = npos)
{string s;size_t end = pos + len;if (len == npos || end >= _size) // 取到结尾{// len为字串的sizelen = _size - pos; // end >=_sizeend = _size;}s.reserve(len);for (size_t i = pos; i < end; i++){s += _str[i];}return s;
}

值得说的是从pos开始指定取的len如果太长超过结尾,则需要修正取到的len的大小。

源码地址

https://github.com/shlyyy/stl/blob/main/my_string.h

https://gitee.com/shlyyy/stl/blob/master/my_string.h

相关文章:

string的模拟实现

string的模拟实现 msvc和g下的string内存比较成员变量构造函数与析构函数拷贝构造函数赋值拷贝c_str、size和capacity函数以及重载[]、clear、expand_capacity迭代器与遍历reservepush_back、append、insert字符串比较运算符erase<<流提取 >>流插入resizefindsubst…...

算法练习:查找二维数组中的目标值

题目&#xff1a; 编写一个高效的算法来搜索矩阵 matrix 中的一个目标值 target 。该矩阵具有以下特性&#xff1a;每行的元素从左到右升序排列。每列的元素从上到下升序排列。 实现&#xff1a; 1. main方法 public static void main(String[] args) {int[][] matrix {{1…...

考研自命题资料、考题如何找

这篇文章是抖音和b站上上传的同名视频的原文稿件&#xff0c;感兴趣的csdn用户可以关注我的抖音和b站账号&#xff08;GeekPower极客力量&#xff09;。同时这篇文章也为视频观众提供方便&#xff0c;可以更加冷静地分析和思考。文章同时在知乎发表。 去年我发布了一个视频&am…...

MySQL 存储引擎和索引类型介绍

1. 引言 MySQL 是一个流行的关系型数据库管理系统&#xff0c;提供多种存储引擎以满足不同的业务需求。本文将介绍几种常见的 MySQL 存储引擎和索引类型比较&#xff0c;并给出相应的示例。 2. 存储引擎概述 2.1 InnoDB 存储引擎 InnoDB 是 MySQL 的默认存储引擎&#xff0…...

element-ui table height 属性导致界面卡死

问题: 项目上&#xff0c;有个点击按钮弹出抽屉的交互, 此时界面卡死 原因分析: 一些场景下(父组件使用动态单位/弹窗、抽屉中使用), element-ui 的 table 会循环计算高度值, 导致界面卡死 github 上的一些 issues 和解决方案: Issues ElemeFE/element GitHub 官方讲是升…...

Vue2.v-指令

v-if 在双引号中写判断条件。 <div v-if"score>90">A</div> <div v-else-if"score>80">B</div> <div v-else>C</div>v-on: :冒号后面跟着事件。 为了简化&#xff0c;可以直接用代替v-on:。 事件名“内联语…...

Java中SpringBoot组件集成接入【Knife4j接口文档(swagger增强)】

Java中SpringBoot组件集成接入【Knife4j接口文档】 1.Knife4j介绍2.maven依赖3.配置类4.常用注解使用1.实体类及属性(@ApiModel和@ApiModelProperty)2.控制类及方法(@Api、@ApiOperation、@ApiImplicitParam、 @ApiResponses)3.@ApiOperationSupport注解未生效的解决方法5.…...

继承和多态的详解

文章目录 1. 继承1.1 继承的概念1.3 继承的语法1.3 父类成员访问1.3.1 子类中访问父类的成员变量1.3.2 子类中访问父类的成员方法 1.4 子类构造方法 2.super关键字2.1 super关键字的概念2.2 super和this的区别 3. 在继承中访问限定符的可见性4. 继承方式的分类5. 多态5.1 多态的…...

【Unity】UniTask(异步工具)快速上手

UniTask(异步工具) 官方文档&#xff1a;https://github.com/Cysharp/UniTask/blob/master/README_CN.md URL:https://github.com/Cysharp/UniTask.git?pathsrc/UniTask/Assets/Plugins/UniTask 优点&#xff1a;0GC&#xff0c;可以在任何地方使用 为Unity提供一个高性能&…...

k8s三种常用的项目发布方式

k8s三种常用的项目发布方式 1、 蓝绿发布 2、 金丝雀发布(灰度发布)&#xff1a;使用最多 3 、滚动发布 应用程序升级&#xff0c;面临的最大问题是新旧业务之间的切换。 项目的生命周期&#xff1a;立项----定稿----需求发布----开发----测试-----发布 最后测试之后上线。再…...

Nodejs搭配axios下载图片

新建一个文件夹&#xff0c;npm i axios 实测发现只需保留node_modules文件夹&#xff0c;删除package.json不影响使用 1.纯下载图片 其实该方法不仅可以下载图片&#xff0c;其他的文件都可以下载 const axios require(axios) const fs require(fs) var arrPic [https:…...

强化学习在生成式预训练语言模型中的研究现状简单调研

1. 绪论 本文旨在深入探讨强化学习在生成式预训练语言模型中的应用&#xff0c;特别是在对齐优化、提示词优化和经验记忆增强提示词等方面的具体实践。通过对现有研究的综述&#xff0c;我们将揭示强化学习在提高生成式语言模型性能和人类对话交互的关键作用。虽然这些应用展示…...

python_selenium_安装基础学习

目录 1.为什么使用selenium 2.安装selenium 2.1Chrome浏览器 2.2驱动 2.3下载selenium 2.4测试连接 3.selenium元素定位 3.1根据id来找到对象 3.2根据标签属性的属性值来获取对象 3.3根据xpath语句来获取对象 3.4根据标签的名字获取对象 3.5使用bs4的语法来获取对象…...

面试宝典进阶之关系型数据库面试题

D1、【初级】你都使用过哪些数据库&#xff1f; &#xff08;1&#xff09;MySQL&#xff1a;开源数据库&#xff0c;被Oracle公司收购 &#xff08;2&#xff09;Oracle&#xff1a;Oracle公司 &#xff08;3&#xff09;SQL Server&#xff1a;微软公司 &#xff08;4&#…...

Agisoft Metashape 地面点分类参数设置

Agisoft Metashape 点云分类之地面点分类参数设置 文章目录 Agisoft Metashape 点云分类之地面点分类参数设置前言一、分类地面点参数二、农村及城区有房屋地区二、植被区域分类三、侵蚀半径(Erosion radius)参数设置前言 Agisoft Metashape提供了自动检测地面点的功能,减少…...

计算机科学速成课【学习笔记】(4)——二进制

本集课程B站链接&#xff1a; 4. 二进制-Representing Numbers and Letters with Binary_BiliBili_哔哩哔哩_bilibili4. 二进制-Representing Numbers and Letters with Binary_BiliBili是【计算机科学速成课】[40集全/精校] - Crash Course Computer Science的第4集视频&…...

数据库开发工具Navicat Premium 15 mac软件特色

Navicat Premium 15 mac版是一款数据库开发工具&#xff0c;Navicat Premium 15 Mac版可以让你以单一程序同時连接到 MySQL、MariaDB、SQL Server、SQLite、Oracle 和 PostgreSQL 数据库。 Navicat Premium mac软件特色 无缝数据迁移 数据传输&#xff0c;数据同步和结构同步…...

从零开始构建区块链:我的区块链开发之旅

1.引言 1.区块链技术的兴起和重要性 区块链技术&#xff0c;作为数字化时代的一项颠覆性创新&#xff0c;已经成为当今世界最令人瞩目的技术之一。自比特币的问世以来&#xff0c;区块链技术已经从仅仅支持加密货币发展成为一种具有广泛应用前景的分布式账本技术。其核心优势…...

c JPEG编码,但有错误

#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <sys/ioctl.h> #include <linux/videodev2.h> //v4l2 头文件 #include <strin…...

二级C语言备考1

一、单选 共40题 &#xff08;共计40分&#xff09; 第1题 &#xff08;1.0分&#xff09; 题号:6923 难度:较易 第1章 以下叙述中正确的是 A:C语言规定必须用main作为主函数名,程序将从此开始执行 B:可以在程序中由用户指定任意一个函数作为主函数…...

7.4.分块查找

一.分块查找的算法思想&#xff1a; 1.实例&#xff1a; 以上述图片的顺序表为例&#xff0c; 该顺序表的数据元素从整体来看是乱序的&#xff0c;但如果把这些数据元素分成一块一块的小区间&#xff0c; 第一个区间[0,1]索引上的数据元素都是小于等于10的&#xff0c; 第二…...

React hook之useRef

React useRef 详解 useRef 是 React 提供的一个 Hook&#xff0c;用于在函数组件中创建可变的引用对象。它在 React 开发中有多种重要用途&#xff0c;下面我将全面详细地介绍它的特性和用法。 基本概念 1. 创建 ref const refContainer useRef(initialValue);initialValu…...

逻辑回归:给不确定性划界的分类大师

想象你是一名医生。面对患者的检查报告&#xff08;肿瘤大小、血液指标&#xff09;&#xff0c;你需要做出一个**决定性判断**&#xff1a;恶性还是良性&#xff1f;这种“非黑即白”的抉择&#xff0c;正是**逻辑回归&#xff08;Logistic Regression&#xff09;** 的战场&a…...

Python如何给视频添加音频和字幕

在Python中&#xff0c;给视频添加音频和字幕可以使用电影文件处理库MoviePy和字幕处理库Subtitles。下面将详细介绍如何使用这些库来实现视频的音频和字幕添加&#xff0c;包括必要的代码示例和详细解释。 环境准备 在开始之前&#xff0c;需要安装以下Python库&#xff1a;…...

C++ 求圆面积的程序(Program to find area of a circle)

给定半径r&#xff0c;求圆的面积。圆的面积应精确到小数点后5位。 例子&#xff1a; 输入&#xff1a;r 5 输出&#xff1a;78.53982 解释&#xff1a;由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982&#xff0c;因为我们只保留小数点后 5 位数字。 输…...

dify打造数据可视化图表

一、概述 在日常工作和学习中&#xff0c;我们经常需要和数据打交道。无论是分析报告、项目展示&#xff0c;还是简单的数据洞察&#xff0c;一个清晰直观的图表&#xff0c;往往能胜过千言万语。 一款能让数据可视化变得超级简单的 MCP Server&#xff0c;由蚂蚁集团 AntV 团队…...

管理学院权限管理系统开发总结

文章目录 &#x1f393; 管理学院权限管理系统开发总结 - 现代化Web应用实践之路&#x1f4dd; 项目概述&#x1f3d7;️ 技术架构设计后端技术栈前端技术栈 &#x1f4a1; 核心功能特性1. 用户管理模块2. 权限管理系统3. 统计报表功能4. 用户体验优化 &#x1f5c4;️ 数据库设…...

LangChain知识库管理后端接口:数据库操作详解—— 构建本地知识库系统的基础《二》

这段 Python 代码是一个完整的 知识库数据库操作模块&#xff0c;用于对本地知识库系统中的知识库进行增删改查&#xff08;CRUD&#xff09;操作。它基于 SQLAlchemy ORM 框架 和一个自定义的装饰器 with_session 实现数据库会话管理。 &#x1f4d8; 一、整体功能概述 该模块…...

[论文阅读]TrustRAG: Enhancing Robustness and Trustworthiness in RAG

TrustRAG: Enhancing Robustness and Trustworthiness in RAG [2501.00879] TrustRAG: Enhancing Robustness and Trustworthiness in Retrieval-Augmented Generation 代码&#xff1a;HuichiZhou/TrustRAG: Code for "TrustRAG: Enhancing Robustness and Trustworthin…...

WebRTC调研

WebRTC是什么&#xff0c;为什么&#xff0c;如何使用 WebRTC有什么优势 WebRTC Architecture Amazon KVS WebRTC 其它厂商WebRTC 海康门禁WebRTC 海康门禁其他界面整理 威视通WebRTC 局域网 Google浏览器 Microsoft Edge 公网 RTSP RTMP NVR ONVIF SIP SRT WebRTC协…...