From 905d63142dc14850a51cacb80ca860db65028b51 Mon Sep 17 00:00:00 2001 From: lmj01 Date: Fri, 3 Nov 2023 17:32:43 +0800 Subject: [PATCH] update --- cpl/cplusplus.md | 26 +++++++++++++++++++++++--- database/database.md | 12 ++++++++++++ index/community.md | 8 +++++++- index/computerScience.md | 1 + 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 database/database.md diff --git a/cpl/cplusplus.md b/cpl/cplusplus.md index 765693d..e498c56 100644 --- a/cpl/cplusplus.md +++ b/cpl/cplusplus.md @@ -6,16 +6,20 @@ ## TMP(template metaprogramming) +可参考的内容 + +- [关于C++TMP比较新的解释,叫全面些](https://www.3dgep.com/beginning-cpp-template-programming/) + C++ allows template metaprogramming (TMP), a technique in which so-called templates are used by a compiler to generate temporary source code that is merged with the rest of the source code and then compiled 最初模板编程是指控制代码生成来实现泛型,现在的模板更多指泛型约束、编译期计算、对类型做计算。 -**代码生成** +### **代码生成** C语言使用宏来实现泛型,原理就是替换宏参数,属于编译期的字符串拼接 C语言没有模板是因为其语言抽象能力不够,相比C++的抽象能力模板template来实现泛型,宏的缺点都解决掉了。 -**对类型约束** +### **对类型约束** 函数重载是代码生成的一种方案,template就是先处理函数重载和隐式类型转换上花掉很多时间,报错也是一大推的根本原因。 @@ -48,7 +52,7 @@ void print2(T x) { ``` 其他语言如C#和rust,对泛型的约束是通过where来表达的。 -**编译期计算** +### **编译期计算** - 编译器对常量表达式的优化,如C函数的strlen,在C++中strlen是constexpr的 - 为减少运行时开销,会提前算好一些数据,典型的例子是计算三角函数表这种常量表 @@ -104,5 +108,21 @@ int main() { ``` 允许一个运行期函数前面直接加上constexpr关键字修饰,表示函数既可以在运行期调用,也可以在编译期调用.如果只想在编译期执行函数,使用关键字consteval来修饰. +### **对类型做计算与编译期常量** + +在别的编程语言中类型大多是运行时的, C++允许在编译期对类型进行操作,但是类型不能作为普通值,只能作为模板参数。 + +使用std::variant时,需要从一个类型列表里(variant的模板参数)里面根据类型返回一个索引。 + +对类型做计算不得不用模板元编程,需要在编译期计算的同时实例化模板也得使用模板元编程。 + +把类型当成值的改动是完全不可接受的unacceptable的,这是静态语言的特性,而像rust这样是完全不支持的。但有取巧的方法,把类型映射到编译期确定的值,由于字符串是值,只对字符串进行计算。[C++23的typeid实现类似的映射,而不使用字符串映射。](https://godbolt.org/z/GK4KjqKMc) + +一个较新的编程语言[zig](https://ziglang.org/),它解决了上述的问题,支持编译期的变量,还支持类型作为一等公民(type as value)进行操作,得益于zig独特的comptime机制,被它标记的变量或代码块都在编译期执行的。 + +### 额外其他 + +- 首先满足正确性而非效率性 +在一些数据范围小答案可以枚举,且时间上较为苛刻的,使用暴力枚举得出答案,将答案写入数组中。是指先生成一些数据可直接使用,减少运行的时间,对计算量大的可以这样优化。别人把特定计算放在一些文件中,部署出去的程序就跑得飞快,其他人还好奇为什么你的就这么快。 diff --git a/database/database.md b/database/database.md new file mode 100644 index 0000000..107fea9 --- /dev/null +++ b/database/database.md @@ -0,0 +1,12 @@ +# Database + +## 开源的数据库 +- mysql +- [OceanBase](https://github.com/oceanbase/oceanbase) + +## 事务 +ACID属性 +- 原子性Atomicity +- 一致性Consistency +- 隔离性Isolation +- 持久性Durability \ No newline at end of file diff --git a/index/community.md b/index/community.md index 385cfc5..e2fbfc3 100644 --- a/index/community.md +++ b/index/community.md @@ -7,7 +7,13 @@ - [CAF is an open source implementation of the actor model for C++ featuring lightweight & fast actor implementations, pattern matching for messages, network transparent messaging, and more.](https://www.actor-framework.org/) - [document](https://actor-framework.readthedocs.io/en/stable/Introduction.html) -### Publish/Subscribe messaging paradigm +### Paradigm + +[What,if anything, is a programming paradigm? Robert Harper Carnegie Mellon University April 2017](https://www.cs.cmu.edu/~rwh/papers/paradigms/paradigm.pdf) + +[Programming paradigms for dummies: what every programmer should know](https://blog.acolyer.org/2019/01/25/programming-paradigms-for-dummies-what-every-programmer-should-know/) + +#### Publish/Subscribe messaging paradigm - [Publisher-Subscriber pattern](https://learn.microsoft.com/en-us/azure/architecture/patterns/publisher-subscriber) diff --git a/index/computerScience.md b/index/computerScience.md index 5540c92..ab9d006 100644 --- a/index/computerScience.md +++ b/index/computerScience.md @@ -21,6 +21,7 @@ ### Database +- [database](../database/database.md) - [redis](../database/redis.md) - [MySql](../database/mysql.md) - [sql](../database/sql.md)