coding variable

六月 03, 2022 [c++, 命名] #c++ #命名

coding variable

记录常用变量名 variable name

ceil floor round trancate trim below above foo bar tmp begin end start stop final finish forward back front back prev next fast slow first second last positive negative non-neg un-used less more greater backtrack backtrace pre mid/cur next precursor successor successor/ predecessor/ ancetor master slave low hight left right top bottom up down pivot signed dummy removed visited seen prefix postfix suffix/surfix head tail node L1 size len1 dp visited helper memo mapping remove erase middleNode removeTail moveToHead addToHead cache maxGain INT_MIN dfs bfs carry voted load dead apply state mutex semaphore shm leader candidate follower peer me persister offline disable after before binaraySearch quickSort mergeSort odd even each item index found target ignore delay conclude exclude include extra small big bad good new old recent past history send receive reject avoid accept deep breadth wide short light volumn capacity scope room scope level dual duplicate double copied paired single only alone uniq free busy block hold occupied book bind empty full main chief leader major primary central minor depedency auxiliary subordinate mirror symmetric child children parent father mother mono multi valid invalid check info edge course indegree outdegree token mark sign selected operator operand recursive iterative lhs(left hands side, the left side of equal sign) rhs path

函数名 function name

to_string sprintf(str, "%2d", i) atoi stoi strtoi stoi stol stoll

ostringstream os; os << i; os.str(); queue.back() queue.front() queue.push(val) queue.pop() stack.top() stack.push(val) stack.pop() vec.push_back(val) vec.pop_back() vec.reserve(8) vec.emplace(val) list.push_back(val) list.pop_front() list.reverse()

stack2.push(stack1.top())

str.assign(vec.begin(), vec.end()) str.substr(start, len) str.c_str()

queue.back() queue.front() queue.push() queue.pop()

stack.top() stack.push() stack.pop()

vec.push_back() vec.pop_back() vec.reserve()

list.push_back() list.pop_front() list.reverse()

int maxNum = *max_element(nums.begin(), nums.end()

lower_bound(vec.begin(), vec.end(), target, less())

mymap.erase(it); mymap.erase('c'); mymap.erase(mymap.begin(), mymap.begin()+1) mymap.lower_bound(key1);

vec.erase(remove(vec.begin(), vec.end(), 1), vec.end())

(algorithm)remove算法并不是直接把元素删除,而是用后面的元素替代前面的元素 应该使用list的remove成员函数,而不是remove算法!

iota(v.begin(), v.end(), 1); std::addressof std::result_of

vector vec2(vec1.size()); vec2.resize(vec1.size()); partial_sum(vec1.begin(), vec1.end(), vec2.begin());

迭代器的辅助函数

STL中"萃取机"

nth_element(v.begin(), v.begin()+2, v.end()); int size = distance(v.begin(), v.end()); advance(p, n):使迭代器 p 向前或向后移动 n 个元素. distance(p, q):计算两个迭代器之间的距离,即迭代器 p 经过多少次 + + 操作后和迭代器 q 相等.如果调用时 p 已经指向 q 的后面,则这个函数会陷入死循环. iter_swap(p, q):用于交换两个迭代器 p,q 指向的值.

split string

https://zhuanlan.zhihu.com/p/426939341

使用正则表达式

std::vector<std::string> stringSplit(const std::string& str, char delim) {
    std::string s;
    s.append(1, delim);
    std::regex reg(s);
    std::vector<std::string> elems(std::sregex_token_iterator(str.begin(), str.end(), reg, -1),
                                   std::sregex_token_iterator());
    return elems;
}

stringstream和getline配合使用

std::vector<std::string> stringSplit(const std::string& str, char delim) {
    std::stringstream ss(str);
    std::string item;
    std::vector<std::string> elems;
    while (std::getline(ss, item, delim)) {
        if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

string trim

s.erase(0, s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" "));

定制比较函数cmp

auto cmp = ->bool { return i>j; }; priority_queue<int,vector,decltype(cmp)> pq;

头文件

<limits.h>
<stdlib.h>
<unistd.h>










<type_traits>


名词介绍

NLL:Non-lexical lifetimes (NLL Rust)

PV: P,V原语中P是荷兰语的Passeren,相当于英文的pass, V是荷兰语的Verhoog,相当于英文中的increment

comprehension

ELF: Executable and Linking Format pic: position-independent code pie: position independent executable got: Global Offset Table plt: Procedure Linkage Table GDT: Global Descriptor Table LDT: Local Descriptor Table LDT(Local Descriptor Table),与GDT不同的是,LDT在系统中可以存在多个,并且从LDT的名字可以得知,LDT不是全局可见的,它们只对引用它们的任务可见,每个任务最多可以拥有一个LDT, 另外,每一个LDT自身作为一个段存在,它们的段描述符被放在GDT中. IDTR: 中断描述符表寄存器 ASLR: Address space layout randomization

payload(有效攻击负载):是包含在你用于一次漏洞利用(exploit)中的ShellCode中的主要功能代码 shellcode(可提权代码):对于一个漏洞来说,ShellCode就是一个用于某个漏洞的二进制代码框架, 有了这个框架你可以在这个ShellCode中包含你需要的Payload来做一些事情 shellcode---也是一种payload exp(Exploit ):漏洞利用,一般是个demo程序 poc.(Proof of Concept):漏洞证明,一般就是个样本 用来证明和复现 vul(Vulnerability):漏洞 "Pwn":是一个黑客语法的俚语词 ,是指攻破设备或者系统,from own cve---漏洞编号,漏洞字典,国际上的 cnvd---漏洞编号,漏洞字典,咱们自己的 0day---没打补丁,没公开的漏洞 payload---渗透目标后执行的代码 apt---Advanced Persistent Threat 高级可持续性攻击 rop

技巧方法

  1. 原地哈希 使用负数

footprint

https://www.hakuya.work/index.php/2022/07/15/225/

Rust

trait对象需要类型安全

只有对象安全(object-safe)的trait可以实现为特征对象。这里有一些复杂的规则来实现trait的对象安全,但在实践中,只有两个相关的规则。如果一个 trait 中定义的所有方法都符合以下规则,则该 trait 是对象安全的:

  • 返回值不是 Self
  • 没有泛型类型的参数

变量命名

为什么定义全局常量变量名前面往往加上一个k?

1、因为constant 的发音[ˈkɑ:nstənt],为了简写就使用了k而不是c。

2、习惯的原因,以前的很多编程命名规范中,c代表char,一般不用c来做前缀指示常量;德语中konstant是常量的意思,同时数学上也经常用k来代表常量,因此常用k来做常量的前缀指示。

缩写

rcu: read copy update
cow: copy on write / eager copy
cas: compare and swap                                                       │
柯里化,偏函数,thunk,仿函数
协变, 逆变
ADT(Abstract Data Type)
代码中的魔鬼数字 : 在代码中没有具体含义的数字、字符串
SFINAE (Substitiution Faliure is Not an Error)
NTTP (non-type template parameter)
CRTP (Curiously Recurring Template Pattern):enable_shared_from_this
PIMPL (Private Implementation 或 Pointer to Implementation)
SSO(Small String Optimization)
std::pmr::memory_resource/ pmr是polymorphic memory resource的缩写
AASI allocator aware software interface
GDT Global Descriptor Table: GDTR (GDT register)
LDT Local Descriptor Table 局部描述符表可以有若干张,每个任务可以有一张; 我们可以这样理解GDT和LDT:GDT为一级描述符表,LDT为二级描述符表
PCB (Processing Control Block)
TSS 段其实就是PCB中的一个子段
IoC Inversion of Control (控制反转/反转控制)
DI: Dependancy Injection(依赖注⼊)
AOP: Aspect oriented Programming ⾯向切⾯编程/⾯向⽅⾯编程
CVE(Common Vulnerabilities & Exposures)通用漏洞披露
CWE Common Weakness Enumeration 通用缺陷枚举
CLASP(Comprehensive Lightweight Application Security Process)
UAF(Use-After-Free)
RSI: Repetitive Strain Injury 腕管综合征
NLL: Non-lexical lifetimes
GOT: Global Offset Table
PLT: Procedure Linkage Table
RAII (Resource Acquisition Is Initialization)
RTTI: Runtime Type Information  意思是运行时类型信息,它提供了运行时确定对象类型的方法
CSRF: Cross-Site Request Forgery
CORS: Cross-Origin Resource Sharing

web http 概念

Claims : 是JSON Web Token(JWT) 的核心概念,用于存储用户身份验证信息的结构化数据。
Trailer: HTTP协议中的Trailer头部字段, 用于分块传输编码(Chunked Transfer Encoding)的响应中,将某些HTTP头部字段延迟到消息体之后发送,如校验和,处理状态等,例如在最后的一个分块后附加响应头: Trailer: X-Checksum