<aside> 💡 unique_ptr、矩阵相乘、gdb等。

</aside>

代码下载

  1. 按照项目下的文档步骤:

    // 1. 新建一个仓库 bustub-private
    // 2. clone cmu db 远程代码到本地
    git clone --bare <https://github.com/cmu-db/bustub.git> bustub-public
    cd bustub-public
    // 3. mirror到自己刚创建的远程仓库
    git push --mirror [email protected]:sunshinejiali/bustub-private.git
    // 4. 删除 cmu db 的本地副本
    cd ..
    rm -rf bustub-public
    // 5. 拉取自己的远程仓库代码
    git clone [email protected]:sunshinejiali/bustub-private.git
    // 6. 添加 cmu-db 作为自己的第二远程仓库
    cd bustub-private
    git remote add public <https://github.com/cmu-db/bustub.git>
    // 7. 验证是否已经添加
    git remote -v
    // result:
    // origin  [email protected]:sunshinejiali/bustub-private.git (fetch)
    // origin  [email protected]:sunshinejiali/bustub-private.git (push)
    // public  <https://github.com/cmu-db/bustub.git> (fetch)
    // public  <https://github.com/cmu-db/bustub.git> (push)
    // 8. 提取 cmu-db 中的更改
    git pull public master
    
  2. 使用 2020 年的版本,因此需要回退到之前提交的某一版本。

    // 将代码回退到某一版本,head 指向当前的目标版本,删除之后的所有版本
    git reset --hard 444765a
    // 检查一下是否回退到正确的版本
    git log
    // (强制)提交更改
    git push -f
    
  3. 报错

  4. 编译

    mkdir build
    cd build
    cmake ..
    make
    // 测试
    cd ..
    cd build
    make check-tests
    

C++教程

  1. for 循环

    // 使用引用,允许修改数组中的元素。
    for(int& i: someDataStructure) { doSomething();}
    // 显示数组中的值,并保护数组成员,启用按值访问,不允许修改元素。
    for(int i: someDataStructure) doSomething();
    
  2. Lambda 函数的 Lamba 表达式——有主体但没有名字的函数

    // firstPart 用于将在 lambda 函数内部利用的变量范围。
    [firstPart](secondPart) TypeYouReturn{ BodyOfLambda}(acctualParameters);
    
    // 例子1
    double dUpperPart = [](double dX, double dY)double{ return dX*dX +dY*dY;}
    
    // 例子2
    vectror<int> iVector;
    for_each( begin(iVector), end(iVector), [](int n){if(n%2==0)cout<<n<<end;});
    
  3. Static Assertion

    // 两部分:(1)需要判断的表达式。(2)不匹配显示的消息。
    static_assert(evaluatedExpression, stringMessage);
    // 例子
    static_assert(sizeof(long long int)>=16;”This is unexpected”);
    
  4. Move and &&

    // 在类中实现移动构造函数
    MovableClass(MovableClass&&);
    // 需要移动配置的时候,这样调用
    MovableClass&& operator=(MovableClass&&);
    
  5. 指针

  6. 统一初始化和初始化列表

    如果希望使用构造函数,最好用 {} 替换旧样式的初始化 ()

  7. 构造函数和继承

    class CSomeClass
    {
    private:
    	int nSomeValue=0;
    ...
    }
    
    class CChild: public CParent 
    { 
    public: 
    using CParent::CParent   
    }
    
  8. 虚函数

  9. 多线程

  10. 编程风格

    auto tuple = make_tuple(“triangle”, ‘t’, 10, 15, 20);
    
    // 将具有一个元素字符串而另一个是向量的映射
    map<string,vector<int>> aMap;
    

GDB教程

  1. 如果想要调试 main 函数。

    gdb main
    // or gdb a.out
    // 运行
    run
    // or start
    // 回溯,看是哪里的问题
    backtrace
    // 查看某个地址处的值, x 可以看作是 examine 的缩写。
    x 0xffbef014
    
  2. 条件和断点

    // 打断点,在第 52 行。
    break LinkedList<int>::remove
    
    // 仅在 item_to_remove 等于 1 时,在第 52 行中断。
    condition 1 item_to_remove==1