美文网首页
ARTS Week 1

ARTS Week 1

作者: Yangbin | 来源:发表于2018-11-18 20:50 被阅读0次

Algorithm:

Problem: Reorder Log Files
Answer:

bool logCompare(string log1, string log2)
{
    int p1 = log1.find(' ');
    int p2 = log2.find(' ');
    if (!isdigit(log1[p1+1]) && !isdigit(log2[p2+1])) {
        return log1.substr(p1 + 1) < log2.substr(p2 + 1);
    }
    else {
        if (!isdigit(log1[p1+1])) 
            return true;
        return false;
    }
}

class Solution {
public:
    vector<string> reorderLogFiles(vector<string>& logs) {
        stable_sort(logs.begin(), logs.end(), logCompare);
        return logs;
    }
};

Review:

(Not completed, will continue next week.)
Article: The Log: What every software engineer should know about real-time data's unifying abstraction
Notes:

A log is really just a kind of table or file where the records are sorted by time.
Logs have a specific purpose: they record what happened and when.

Logs in databases

Over-time the usage of the log grew from an implementation detail of ACID to a method for replicating data between databases.

Logs in distributed systems

The purpose of the log here is to squeeze all the non-determinism out of the input stream to ensure that each replica processing this input stays in sync.

Database people generally differentiate between physical and logical logging. Physical logging means logging the contents of each row that is changed. Logical logging means logging not the changed rows but the SQL commands that lead to the row changes (the insert, update, and delete statements).
The distributed systems literature commonly distinguishes two broad approaches to processing and replication.


Changelog 101: Tables and Events are Dual

Tables support data at rest and logs capture change.
Log is a sort of backup of every previous state of the table.
A version control system usually models the sequence of patches, which is in effect a log.

Tip:

When you want to test a new feature of your project. You want to select 10% of the users to test if the feature is welcome. You can use the hash of userId to decide if the feature is open to the user.

e.g. The range of hashCode is -2147483648 to -2147483647.
If you want to select 10% users, you can do it like below:

bool openNewFeature(string userId)
{
    if (abs(hashCode(userId)) <  10 * 21474836) 
        return true;
    else 
        return false;
}

A way to control the Roll Up when you want to

Share:

后端架构师技术图谱
To my knowledge, I can't identify weather it is a good guide. But at least we can know what kind of knowledge we should learn it we want to be an architect. And it also provides many resources.

Follow Up:

  1. Complete the article
  2. Paxos Algorithm

相关文章

  • ARTS Week 1

    Algorithm: Problem: Reorder Log FilesAnswer: Review: (Not...

  • ARTS-WEEK1

    左耳听风ARTS 100天打卡计划 (1)Algorithm 每周至少做一个 leetcode 的算法题-为了编程...

  • ARTS-Week 1

    Algorithm 两数之和 题目:给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为...

  • ARTS Week 01

    Algorithm 题目 977. 有序数组的平方给定一个按非递减顺序排序的整数数组 A,返回每个数字的平方组成的...

  • ARTS Week 02

    Algorithm 832. 翻转图像 题目 给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果...

  • ARTS Week 03

    Algorithm 905. 按奇偶排序数组 题目 给定一个非负整数数组 A,返回一个由 A 的所有偶数元素组成的...

  • ARTS Week 06

    Algorithm 1021. 删除最外层的括号 有效括号字符串为空 ("")、"(" + A + ")" 或 A...

  • ARTS Week 04

    Algorithm 题目 922. 按奇偶排序数组 II 给定一个非负整数数组 A, A 中一半整数是奇数,一半整...

  • ARTS Week 05

    Algorithm 题目 771. 宝石与石头 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头。...

  • ARTS-Week0

    每周完成一次 ARTS 编程挑战,坚持做有积累效应的事情。Algorithm:每周至少做一道 [LeetCode...

网友评论

      本文标题:ARTS Week 1

      本文链接:https://www.haomeiwen.com/subject/dlebfqtx.html