Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Philip Schwarz
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Haskell, Scala and Java.
Inspired by the example in Scott Wlaschin’s F# book: Domain Modeling Made Functional.
Download for better results.
Java 19 Code: https://github.com/philipschwarz/fruit-salad-and-fruit-snack-ADT-example-java
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Philip Schwarz
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Haskell, Scala and Java.
Inspired by the example in Scott Wlaschin’s F# book: Domain Modeling Made Functional.
Download for better results.
Java 19 Code: https://github.com/philipschwarz/fruit-salad-and-fruit-snack-ADT-example-java
Les designs patterns présentés autrement. Du besoin vers le pattern pour avoir un cas concret d'application et pour mieux comprendre l'application.
Les étudiants ont aimé la démarche et leurs retours étaient positifs. Donc j'ai décidé de le partager avec vous.
J'attends vos retours aussi ;)
Enjoy :)
Alexander Sapin from Yandex presents reasoning, design considerations, and implementation of ClickHouse Keeper. It replaces ZooKeeper in ClickHouse clusters, thereby simplifying operation enormously.
Microbenchmarks are like a microscope. Magnification is high, but what the heck are you looking at? Like "truths, half-truths, and statistics", microbenchmarks can be very misleading. In this presentation, learn how to tell when a benchmark lies, recognize what a benchmark can really tell you and understand how some popular benchmarks are flawed.
Les designs patterns présentés autrement. Du besoin vers le pattern pour avoir un cas concret d'application et pour mieux comprendre l'application.
Les étudiants ont aimé la démarche et leurs retours étaient positifs. Donc j'ai décidé de le partager avec vous.
J'attends vos retours aussi ;)
Enjoy :)
Alexander Sapin from Yandex presents reasoning, design considerations, and implementation of ClickHouse Keeper. It replaces ZooKeeper in ClickHouse clusters, thereby simplifying operation enormously.
Microbenchmarks are like a microscope. Magnification is high, but what the heck are you looking at? Like "truths, half-truths, and statistics", microbenchmarks can be very misleading. In this presentation, learn how to tell when a benchmark lies, recognize what a benchmark can really tell you and understand how some popular benchmarks are flawed.
27. Banker Algorithm 範例練習
④為Safety Algorithm做前提的變數假設,設想系統借資源給Process i之後
的情形:
Allocation[i, 1..m] += Request(i)[1..m]
Need[i, 1..m] -= Request(i)[1..m]
Available[1..m] -= Request(i)[1..m]
27
Request
A B C
1 0 2P1
Available
A B C
2 3 0
Allocation
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
Available
A B C
3 3 2
Allocation
A B C
0 1 0
3 0 2
3 0 2
2 1 1
0 0 2
Need
A B C
7 4 3
0 2 0
6 0 0
0 1 1
4 3 1
Need
A B C
7 4 3
1 2 2
6 0 0
0 1 1
4 3 1
→ → →
28. Banker Algorithm 範例練習
⑤- ①執行Safety Algorithm
Work[1..m] = Available[1..m]
Finish[1..n] = false
28
Available
A B C
2 3 0
Work
A B C
2 3 0
P0
P1
P2
P3
P4
Finish
false
false
false
false
false
=
29. Banker Algorithm 範例練習
⑤- ②模擬資源的分發:
while(Finish[i]==false && Need[i, j]<=Work){
Finish[i] ==true
Work[j] += Allocation[i, j]
}
29
Work
A B C
2 3 0
P0
P1
P2
P3
P4
Finish
false
false
false
false
false
Need
A B C
7 4 3
0 2 0
6 0 0
0 1 1
4 3 1
Allocation
A B C
0 1 0
3 0 2
3 0 2
2 1 1
0 0 2
Safety Queue
<null>
P0
P1
P2
P3
P4
30. Banker Algorithm 範例練習
⑤- ②模擬資源的分發:
while(Finish[i]==false && Need[i, j]<=Work){
Finish[i] ==true
Work[j] += Allocation[i, j]
}
30
Work
A B C
2 3 0
P0
P1
P2
P3
P4
Finish
false
true
false
false
false
Need
A B C
7 4 3
0 2 0
6 0 0
0 1 1
4 3 1
Allocation
A B C
0 1 0
3 0 2
3 0 2
2 1 1
0 0 2
Safety Queue
<P1>
Work
A B C
5 3 2→
+(3, 0, 2)
其實真實是先-(0, 2, 0)再+(3, 2, 2)
P0
P1
P2
P3
P4
31. Banker Algorithm 範例練習
⑤- ②模擬資源的分發:
while(Finish[i]==false && Need[i, j]<=Work){
Finish[i] ==true
Work[j] += Allocation[i, j]
}
31
Work
A B C
5 3 2
P0
P1
P2
P3
P4
Finish
false
true
false
true
false
Need
A B C
7 4 3
0 0 0
6 0 0
0 1 1
4 3 1
Allocation
A B C
0 1 0
0 0 0
3 0 2
2 1 1
0 0 2
Safety Queue
<P1, P3>
Work
A B C
7 4 3→
+(2, 1, 1)
其實真實是先-(0, 1, 1)再+(2, 2, 2)
P0
P1
P2
P3
P4
32. Banker Algorithm 範例練習
⑤- ②模擬資源的分發:
while(Finish[i]==false && Need[i, j]<=Work){
Finish[i] ==true
Work[j] += Allocation[i, j]
}
32
Work
A B C
7 4 3
P0
P1
P2
P3
P4
Finish
false
true
false
true
true
Need
A B C
7 4 3
0 0 0
6 0 0
0 0 0
4 3 1
Allocation
A B C
0 1 0
0 0 0
3 0 2
0 0 0
0 0 2
Safety Queue
<P1, P3, P4>
Work
A B C
7 4 5→
+(0, 0, 2)
其實真實是先-(4, 3, 1)再+(4, 3, 3)
P0
P1
P2
P3
P4
33. Banker Algorithm 範例練習
⑤- ②模擬資源的分發:
while(Finish[i]==false && Need[i, j]<=Work){
Finish[i] ==true
Work[j] += Allocation[i, j]
}
33
Work
A B C
7 4 5
P0
P1
P2
P3
P4
Finish
true
true
false
true
true
Need
A B C
7 4 3
0 0 0
6 0 0
0 0 0
0 0 0
Allocation
A B C
0 1 0
0 0 0
3 0 2
0 0 0
0 0 0
Safety Queue
<P1, P3, P4, P0>
Work
A B C
7 5 5→
+(0, 1, 0)
其實真實是先-(7, 4, 3)再+(7, 5, 3)
P0
P1
P2
P3
P4
34. Banker Algorithm 範例練習
⑤- ②模擬資源的分發:
while(Finish[i]==false && Need[i, j]<=Work){
Finish[i] ==true
Work[j] += Allocation[i, j]
}
34
Work
A B C
7 5 5
P0
P1
P2
P3
P4
Finish
true
true
true
true
true
Need
A B C
0 0 0
0 0 0
6 0 0
0 0 0
0 0 0
Allocation
A B C
0 0 0
0 0 0
3 0 2
0 0 0
0 0 0
Safety Queue
<P1, P3, P4, P0, P2>
Work
A B C
10 5 7→
+(3, 0, 2)
其實真實是先-(6, 0, 0)再+(9, 0, 2)
P0
P1
P2
P3
P4