Contents

ARST打卡第208周[208/521]

Algorithm

lc2418_按身高排序

思路: 因为这个名字和身高是分离的数组,不能通过直接写一个对比身高的函数来直接调整名字,因为快排中需要后续持续比较,所以可以容易地想到方法一就是把名字和身高联系起来,以方便一起变动

  • 方法1. 通过把名字身高搞成一个结构体数组,然后再用身高对结构体数组排序

  • 方法2. 还有一种思路,就是通过记录身高对应的原始的下标,最后sort排序之后,遍历现在的身高,把原来的下标位置的名字和当前身高下标的名字依次swap(如果相等则不用swap)

发现题解和我的思路一毛一样,只不过我的swap,变成了题解的直接遍历获取,多用了一些空间,问题不大

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// g++ A.cpp -o A.out -std=c++11
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    vector<string> sortPeople(vector<string>& names, vector<int>& heights) {
        int n = names.size();
        vector<int> indices(n);
        // Create a range of sequentially increasing values. For each element in the range [first,last) assigns value and increments value as if by ++value.
        iota(indices.begin(), indices.end(), 0);
        // for (int i = 0; i < n; i++) {
        //     printf("第 %d 个, value: %d \n", i, indices[i]);
        // }
        // indices记录原来的下标,根据高度排序下标后,当前第一的下标的就是最高的下标,然后直接读原下标映射
        // indices一开始用0,1,2的value锁死绑定height的0,1,2号下标,然后用indices来代替heights数组进行快排换位置,每次换了位置之后,
        // 相当于高度换了位置,所以能最终是indices是按照高度降序的,也就是记录来原来的下标
        // 因为今天工作强度比较大,晚上脑子不够用了,加上对匿名表达式用得少(下面是引用),在这个小问题上卡了一个小时...
        sort(indices.begin(), indices.end(), [&](int x, int y) {
            return heights[x] > heights[y];
        });
        // for (int i = 0; i < n; i++) {
        //     printf("第 %d 个, value: %d \n", i, indices[i]);
        // }
        vector<string> res(n);
        for (int i = 0; i < n; i++) {
            res[i] = names[indices[i]];
        }
        return res;
    }
};

int main() {
    Solution sol;
    string name[3] = {"Mary","John","Emma"};
    int a[3] = {180,165,170};
    vector<string> names(name, name+3);
    vector<int> tmp_v(a, a+3);
    vector<string> ans = sol.sortPeople(names, tmp_v);
    for (int i = 0; i < names.size(); i++) {
        cout << ans[i] << endl; 
    }
    return 0;
}

Review

The birth of RocksDB-Cloud

解决的痛点 / 优势:

  • 防止Rocksdb单节点故障 A RocksDB-Cloud instance is durable. Continuous and automatic replication of db data and metadata to Cloud Storage (e.g. AWS S3). In the event that the RocksDB-Cloud machine dies, another process on any other EC2 machine can reopen the same RocksDB-Cloud database.

  • 方便克隆拷贝rocksdb实例 A RocksDB-Cloud instance is cloneable. RocksDB-Cloud supports a primitive called zero-copy-clone that allows another instance of RocksDB-Cloud on another machine to clone an existing db. Both master and slave RocksDB-Cloud instance can run in parallel and they share some set of common database files.

  • 冷热数据分离,自动把冷数据放在云存储 A RocksDB-Cloud instance automatically places hot data in SSD and cold data in Cloud Storage. The entire database storage footprint need not be resident on costly SSD. The Cloud storage contains the entire database and the local storage contains only the files that are in the working set.

  • 降本的特性 The reason you might want to use rocksdb-cloud is not because replication is quicker in rocksdb-cloud. You would use rocksdb-cloud because of its storage efficiency and reduced cost.

Storage efficiency comes from better packing of data in rocksdb. Reduced-cost comes from the fact that you do not need to keep only one copy of your data in SSD/RAM whereas you need to keep two/three copies of your data in SSD/RAM while using cassandra.

Tips

LSM-tree 的 Remote Compaction调度

Share-个人能量 & 开阔视野

前deepin大佬,现创业者关于个人学习的分享

管理能量,专注事情,学习成长,不要急