todo
question | method? |
---|---|
delete node in BST | recursive |
dp | |
quick select | |
union find | |
palindrome substring | dp做 |
todo
question | method? |
---|---|
delete node in BST | recursive |
dp | |
quick select | |
union find | |
palindrome substring | dp做 |
Case : 来看两个共享counter变量的进程
Process 1
1 | while (true) { |
Process 2
1 | while (true) { |
在执行时
1 | counter++ |
相当于下面三行代码
1 | register1 = counter |
且
1 | counter-- |
相当于
1 | register2 = counter |
有可能下面的情况出现
(此处感谢
https://myfavs.win/2019/08/08/%E8%AE%B0%E5%BD%95-Hexo-%E5%9B%BE%E7%89%87%E7%9A%84%E5%9D%91/
解决了图片问题)
The important feature of the system is that, when one process is executing in its critical section, no other process is allowed to execute in its critical section. That is, no two processes are executing in their critical sections at the same time. The critical-section problem is to design a protocol that the processes can use to cooperate.
理解一下:一个进程在critical section里执行的时候,其他程序不可以进来。否则就会出现上述情况中的问题
If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.
基本就是字面意思
If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in deciding which will enter its critical section next, and this selection cannot be postponed indefinitely.
中文翻译: 如果没有进程在其临界区内执行且有进程需进入临界区,那么只有那么不在剩余区内执行的进程可参加选择,以确定谁能下一个进入临界区,且这种选择不能无限推迟;(wtf?????)
研究一番之后的理解:所有程序都在make progress而不是傻等。
There exists a bound, or limit, on the number of times that other processes are allowed to enter their critical sections after a entry section critical section exit section.
每个程序都会进入critical section 而不是starve forever.
There is a process on how versions change.
https://www.geeksforgeeks.org/dekkers-algorithm-in-process-synchronization/
Given a class below :
1 | // Can you spot the bug? (Page 188) |
If we don’t add Override annotation, equals method will not work.
Actually we want to override equals and even hashCode method, however, there is no @Override annotation.
Also the type of parameter we pass into equals method is wrong,(should be Object).
So overloading happens instead of overriding.
Whatever we do in Set s, s deals with different element within it by Object.equals method :
1 | /** |
So there are different 260 objects in s.
clutter : 混乱
deem : 认为
Redux architecture revolves around a strict unidirectional data flow.
from anywhere in your app, including components and XHR callbacks, or even at scheduled intervals.
The store will pass two arguments to the reducer: the current state tree and the action.
1 | // The current application state (list of todos and chosen filter) |
Note that a reducer is a pure function. It only computes the next state. It should be completely predictable: calling it with the same inputs many times should produce the same outputs. It shouldn’t perform any side effects like API calls or router transitions. These should happen before an action is dispatched.
This new tree is now the next state of your app! Every listener registered with store.subscribe(listener) will now be invoked; listeners may call store.getState() to get the current state.
Now, the UI can be updated to reflect the new state. If you use bindings like React Redux, this is the point at which component.setState(newState) is called.
The state of your whole application is stored in an object tree within a single store.
The only way to change the state is to emit an action, an object describing what happened.
To specify how the state tree is transformed by actions, you write pure reducers.
Actions are payloads of information that send data from your application to your store. They are the only source of information for the store. You send them to the store using store.dispatch().
Reducers specify how the application’s state changes in response to actions sent to the store. Remember that actions only describe what happened, but don’t describe how the application’s state changes.
We’ll explore how to perform side effects in the advanced walkthrough. For now, just remember that the reducer must be pure. Given the same arguments, it should calculate the next state and return it. No surprises. No side effects. No API calls. No mutations. Just a calculation.
The Store is the object that brings Actions and Reducers together.
The store has the following responsibilities:
1 | import { createStore } from 'redux' |
It’s important to note that you’ll only have a single store in a Redux application. When you want to split your data handling logic, you’ll use reducer composition instead of many stores.
https://redux.js.org/introduction/three-principles
Learning Resources: https://redux.js.org/introduction/learning-resources
Show all shell scripts path
If you have 2 folders that contain the same command, it will run the first one
1 | which cal //show which folder which is in |
1 | date -u - for short form |
1 | touch |
##Manual Structure
1 | man -k which |
###help page
man cd : no result
help cd : show cd info
just type help and it will show the command that needs help
The only way to change the state is to emit an action, an object describing what happened.
###cat
0:input
1:output
2:error
1 | cat > output.txt // create a file and then put data stream out this file |
It’s important to note that you’ll only have a single store in a Redux application. When you want to split your data handling logic, you’ll use reducer composition instead of many stores.
https://redux.js.org/introduction/three-principles
Learning Resources: https://redux.js.org/introduction/learning-resources
1 | c = 100; |
https://www.codementor.io/@dariogarciamoya/understanding-this-in-javascript-with-arrow-functions-gcpjwfyuc
https://medium.com/tfogo/advantages-and-pitfalls-of-arrow-functions-a16f0835799e
https://dmitripavlutin.com/when-not-to-use-arrow-functions-in-javascript/
https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1
https://hackernoon.com/javascript-es6-arrow-functions-and-lexical-this-f2a3e2a5e8c4
https://stackoverflow.com/questions/52979915/why-we-dont-need-to-bind-the-arrow-function-in-react
也叫compile 多态,本质就是编译时method的多态性,其实就是方法的overload.
Same method name is overloaded with different type or number of parameters in same class (different signature). Targeted method call is resolved at compile time
也叫runtime 多态,本质是继承属性和函数override的组合。
看过很多文章在讲向上转型(upcasting)和向下转型(downcasting),有的文章讲的非常复杂,研究了一番后打算总结如下。
其实是最简单的一种–人工强制cast。
1 | class Sup{ |
在这里我们进行一个操作
1 | Sup a = new Sub(); |
说白了,向上转型就是
我们不妨换个思考的角度,为什么要 “把自己(自动向上转型)变成父类”???
so 找到之后再从ref 往下 看有没有override的情况然后以new出来的对象为底,结束。
如果形式参数没有怎么办?
答:把形式参数多态向上找。
1 | public class TestForPoli { |
输出结果如下
1 | 1--A and A |
a1 :ref为A,实例为A,向上的关系只有object,show(b)找不到,尝试去找show((super)b)也就是把形式参数向上转型,找到了show(A a)方法,所以输出A and A。
2 3 同理。
a2 :ref为A,实例为B,向上的关系只有object,show(b)找不到,尝试去找show((super)b)就是把形式参数向上转型,找到了show(A a)方法,(到这里和上面是一样的),但是实例为B,我们需要进行的操作是看show(A a)方法有没有被override,然后发现class B里有一个show(A a)的方法,故输出B and A
5 同理,6是因为A里直接有一个show(D d)的method,而且这个方法没有被实例B override,故输出A and D
7 easy
这里我们使用向上转型继承的方法,把b的super类a的方法都加到b里,然后还是没有找到show(B)的办法,我们此时就去找形式参数c的super类,向上找到了B,于是输出B and B
这里我们使用向上转型继承的方法,把b的super类a的方法都加到b里,解决。