Contents

ARST打卡第281周

lc2374_边积分最高的节点 【TED】你是否为退休储蓄了足够的钱? TiFS, a TiKV-Based Partition Tolerant, Strictly Consistent File System Rust编程范式

Algorithm

lc2374_边积分最高的节点

思路:

就是直接给每个节点记录分数,然后O(n)遍历一遍,然后返回分数最高的节点。

这里的注意点就是爆 int 的问题,所以需要用 long long (i64)来记录分数。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
impl Solution {
    pub fn edge_score(edges: Vec<i32>) -> i32 {
        let mut score = vec![0i64; edges.len()];
        for i in 0..edges.len() {
            score[edges[i] as usize] += i as i64;
        }
        let mut max_score = 0i64;
        let mut max_index = 0;
        for i in 0..score.len() {
            if score[i] > max_score {
                max_score = score[i];
                max_index = i;
            }
        }
        max_index as i32
    }
}

思路和题解一样。

Review

你是否为退休储蓄了足够的钱?

实际上就是按照每月开支,然后去计算退休后每个月需要多少钱,然后去计算需要存多少钱。

演讲者说的375倍准则,实际上就是年化3.2%的收益率: 1/(0.032/12) = 375.

所以比如说退休后一个月开支是 1w,那么就是退休前攒 1w * 375 = 375w。

每年攒 15w (实际也许是平均9w,但是考虑投资复利算15w),那么就是 375/15 = 25 年。

假如25岁开始工作,那么就是 25 + 25 = 50 岁可以退休。

Tips

TiFS, a TiKV-Based Partition Tolerant, Strictly Consistent File System

However, the redundancy ratio is as low as 1.2~1.5 in other distributed file systems that support redundancy by erasure coding (EC), such as HDFS, CephFS, and JuiceFS. EC redundancy requires encoding and decoding during data write and reconstruction, which consumes extra computing resources. However, the EC redundancy strategy sacrifices part of the read performance in exchange for lower network overhead and storage cost.

Currently, it is somewhat difficult for TiKV to support EC, but we plan to support EC-redundancy object storage for file blocks to reduce storage cost.

此文用 TiKV 实现了一个 Filesystem,并且后续将会把文件块内容迁移到对象存储。

非常有意思。可以借鉴方案尝试给 TiKV 实现文件语义。

TiFS github作者好像在juicefs上班,关注了

Share

Rust 编程范式

非常感谢耗子叔的这篇文章,让 C++ 程序员对 Rust 的编程范式有了一个关联 C++ 的视角的认识。

对 Rust 理解瞬间加深,简直是 C++ 程序员学习 Rust 的必看文章。