Skip to content

Commit 2952fd9

Browse files
committedMar 31, 2019
[update] add highlight and space
1 parent 7762d86 commit 2952fd9

File tree

16 files changed

+165
-161
lines changed

16 files changed

+165
-161
lines changed
 

‎chapter03/03.3.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ func main() {
107107
list.PushBack(1)
108108
list.PushBack(2)
109109

110-
fmt.Printf("len: %v\n", list.Len());
111-
fmt.Printf("first: %#v\n", list.Front());
112-
fmt.Printf("second: %#v\n", list.Front().Next());
110+
fmt.Printf("len: %v\n", list.Len())
111+
fmt.Printf("first: %#v\n", list.Front())
112+
fmt.Printf("second: %#v\n", list.Front().Next())
113113
}
114114

115115
output:
@@ -119,7 +119,7 @@ second: &list.Element{next:(*list.Element)(0x2081be150), prev:(*list.Element)(0x
119119
```
120120

121121
list 对应的方法有:
122-
```
122+
```go
123123
type Element
124124
func (e *Element) Next() *Element
125125
func (e *Element) Prev() *Element
@@ -154,7 +154,7 @@ type Ring struct {
154154
}
155155
```
156156

157-
我们初始化环的时候,需要定义好环的大小,然后对环的每个元素进行赋值。环还提供一个 Do 方法,能便利一遍环,对每个元素执行一个 function。
157+
我们初始化环的时候,需要定义好环的大小,然后对环的每个元素进行赋值。环还提供一个 Do 方法,能遍历一遍环,对每个元素执行一个 function。
158158
看下面的例子:
159159

160160
```golang
@@ -188,7 +188,7 @@ sum is 6
188188

189189
ring 提供的方法有
190190

191-
```
191+
```go
192192
type Ring
193193
func New(n int) *Ring // 初始化环
194194
func (r *Ring) Do(f func(interface{})) // 循环环进行操作

‎chapter04/04.2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
相关代码:
1616

17-
```
17+
```go
1818
tz, ok := syscall.Getenv("TZ")
1919
switch {
2020
case !ok:

‎chapter04/04.3.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
`Time` 代表一个纳秒精度的时间点。
44

5-
程序中应使用 Time 类型值来保存和传递时间,而不是指针。就是说,表示时间的变量和字段,应为 time.Time 类型,而不是*time.Time. 类型。一个 Time 类型值可以被多个 go 程同时使用。时间点可以使用 Before、After 和 Equal 方法进行比较。Sub 方法让两个时间点相减,生成一个 Duration 类型值(代表时间段)。Add 方法给一个时间点加上一个时间段,生成一个新的 Time 类型时间点。
5+
程序中应使用 Time 类型值来保存和传递时间,而不是指针。就是说,表示时间的变量和字段,应为 time.Time 类型,而不是 *time.Time. 类型。一个 Time 类型值可以被多个 go 协程同时使用。时间点可以使用 Before、After 和 Equal 方法进行比较。Sub 方法让两个时间点相减,生成一个 Duration 类型值(代表时间段)。Add 方法给一个时间点加上一个时间段,生成一个新的 Time 类型时间点。
66

77
Time 零值代表时间点 January 1, year 1, 00:00:00.000000000 UTC。因为本时间点一般不会出现在使用中,IsZero 方法提供了检验时间是否是显式初始化的一个简单途径。
88

99
每一个 Time 都具有一个地点信息(即对应地点的时区信息),当计算时间的表示格式时,如 Format、Hour 和 Year 等方法,都会考虑该信息。Local、UTC 和 In 方法返回一个指定时区(但指向同一时间点)的 Time。修改地点 / 时区信息只是会改变其表示;不会修改被表示的时间点,因此也不会影响其计算。
1010

11-
通过 == 比较 Time 时,Location 信息也会参与比较,因此 Time 不应该作为 map 的 key。
11+
通过 `==` 比较 Time 时,Location 信息也会参与比较,因此 Time 不应该作为 map 的 key。
1212

1313
## Time 的内部结构
14-
```
14+
```go
1515
type Time struct {
1616
// sec gives the number of seconds elapsed since
1717
// January 1, year 1 00:00:00 UTC.
@@ -33,7 +33,7 @@ type Time struct {
3333

3434
要讲解 `time.Time` 的内部结构,得先看 `time.Now()` 函数。
3535

36-
```
36+
```go
3737
// Now returns the current local time.
3838
func Now() Time {
3939
sec, nsec := now()
@@ -82,7 +82,7 @@ Time.IsZero() 函数用于判断 Time 表示的时间是否是 0 值。
8282

8383
对于解析,要特别注意时区问题,否则很容易出 bug。比如:
8484

85-
```
85+
```go
8686
t, _ := time.Parse("2006-01-02 15:04:05", "2016-06-13 09:14:00")
8787
fmt.Println(time.Now().Sub(t).Hours())
8888
```
@@ -115,7 +115,7 @@ fmt.Println(time.Now().Sub(t).Hours())
115115

116116
对于 json,使用的是 `time.RFC3339Nano` 这种格式。通常程序中不使用这种格式。解决办法是定义自己的类型。如:
117117

118-
```
118+
```go
119119
type OftenTime time.Time
120120

121121
func (self OftenTime) MarshalJSON() ([]byte, error) {
@@ -140,7 +140,7 @@ fmt.Println(t)
140140

141141
使用示例:
142142

143-
```
143+
```go
144144
t, _ := time.ParseInLocation("2006-01-02 15:04:05", "2016-06-13 15:34:39", time.Local)
145145
// 整点(向下取整)
146146
fmt.Println(t.Truncate(1 * time.Hour))

‎chapter04/04.4.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
类型定义如下:
1414

15-
```
15+
```go
1616
type Timer struct {
1717
C <-chan Time // The channel on which the time is delivered.
1818
r runtimeTimer
1919
}
2020
```
2121
C 已经解释了,我们看看 `runtimeTimer`。它定义在 sleep.go 文件中,必须和 `runtime` 包中 `time.go` 文件中的 `timer` 必须保持一致:
2222

23-
```
23+
```go
2424
type timer struct {
2525
i int // heap index
2626

@@ -36,7 +36,7 @@ type timer struct {
3636
```
3737
我们通过 `NewTimer()` 来看这些字段都怎么赋值,是什么用途。
3838

39-
```
39+
```go
4040
// NewTimer creates a new Timer that will send
4141
// the current time on its channel after at least duration d.
4242
func NewTimer(d Duration) *Timer {
@@ -68,7 +68,7 @@ func NewTimer(d Duration) *Timer {
6868

6969
**通过 `time.After` 模拟超时:**
7070

71-
```
71+
```go
7272
c := make(chan int)
7373

7474
go func() {
@@ -88,7 +88,7 @@ case <-time.After(2 * time.Second):
8888

8989
**`time.Stop` 停止定时器 或 `time.Reset` 重置定时器**
9090

91-
```
91+
```go
9292
start := time.Now()
9393
timer := time.AfterFunc(2*time.Second, func() {
9494
fmt.Println("after func callback, elaspe:", time.Now().Sub(start))

‎chapter05/05.1.md

+63-61
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,87 @@ math 包实现的就是数学函数计算。
66

77
正弦函数,反正弦函数,双曲正弦,反双曲正弦
88

9-
- func Sin(x float64) float64
10-
- func Asin(x float64) float64
11-
- func Sinh(x float64) float64
12-
- func Asinh(x float64) float64
9+
- func Sin(x float64) float64
10+
- func Asin(x float64) float64
11+
- func Sinh(x float64) float64
12+
- func Asinh(x float64) float64
1313

1414
一次性返回 sin,cos
1515

1616
- func Sincos(x float64) (sin, cos float64)
1717

1818
余弦函数,反余弦函数,双曲余弦,反双曲余弦
1919

20-
- func Cos(x float64) float64
21-
- func Acos(x float64) float64
22-
- func Cosh(x float64) float64
23-
- func Acosh(x float64) float64
20+
- func Cos(x float64) float64
21+
- func Acos(x float64) float64
22+
- func Cosh(x float64) float64
23+
- func Acosh(x float64) float64
2424

2525
正切函数,反正切函数,双曲正切,反双曲正切
2626

27-
- func Tan(x float64) float64
28-
- func Atan(x float64) float64 和 func Atan2(y, x float64) float64
29-
- func Tanh(x float64) float64
30-
- func Atanh(x float64) float64
27+
- func Tan(x float64) float64
28+
- func Atan(x float64) float64 和 func Atan2(y, x float64) float64
29+
- func Tanh(x float64) float64
30+
- func Atanh(x float64) float64
3131

3232
## 5.1.2 幂次函数 ##
33-
34-
- func Cbrt(x float64) float64 // 立方根函数
35-
- func Pow(x, y float64) float64 // x 的幂函数
36-
- func Pow10(e int) float64 // 10 根的幂函数
37-
- func Sqrt(x float64) float64 // 平方根
38-
- func Log(x float64) float64 // 对数函数
39-
- func Log10(x float64) float64 // 10 为底的对数函数
40-
- func Log2(x float64) float64 // 2 为底的对数函数
41-
- func Log1p(x float64) float64 // log(1 + x)
42-
- func Logb(x float64) float64 // 相当于 log2(x) 的绝对值
43-
- func Ilogb(x float64) int // 相当于 log2(x) 的绝对值的整数部分
44-
- func Exp(x float64) float64 // 指数函数
45-
- func Exp2(x float64) float64 // 2 为底的指数函数
46-
- func Expm1(x float64) float64 // Exp(x) - 1
33+
34+
- func Cbrt(x float64) float64 // 立方根函数
35+
- func Pow(x, y float64) float64 // x 的幂函数
36+
- func Pow10(e int) float64 // 10 根的幂函数
37+
- func Sqrt(x float64) float64 // 平方根
38+
- func Log(x float64) float64 // 对数函数
39+
- func Log10(x float64) float64 // 10 为底的对数函数
40+
- func Log2(x float64) float64 // 2 为底的对数函数
41+
- func Log1p(x float64) float64 // log(1 + x)
42+
- func Logb(x float64) float64 // 相当于 log2(x) 的绝对值
43+
- func Ilogb(x float64) int // 相当于 log2(x) 的绝对值的整数部分
44+
- func Exp(x float64) float64 // 指数函数
45+
- func Exp2(x float64) float64 // 2 为底的指数函数
46+
- func Expm1(x float64) float64 // Exp(x) - 1
4747

4848
## 5.1.3 特殊函数 ##
49-
- func Inf(sign int) float64 // 正无穷
50-
- func IsInf(f float64, sign int) bool // 是否正无穷
51-
- func NaN() float64 // 无穷值
52-
- func IsNaN(f float64) (is bool) // 是否是无穷值
53-
- func Hypot(p, q float64) float64 // 计算直角三角形的斜边长
49+
50+
- func Inf(sign int) float64 // 正无穷
51+
- func IsInf(f float64, sign int) bool // 是否正无穷
52+
- func NaN() float64 // 无穷值
53+
- func IsNaN(f float64) (is bool) // 是否是无穷值
54+
- func Hypot(p, q float64) float64 // 计算直角三角形的斜边长
5455

5556
## 5.1.4 类型转化函数 ##
56-
- func Float32bits(f float32) uint32 // float32 和 unit32 的转换
57-
- func Float32frombits(b uint32) float32 // uint32 和 float32 的转换
58-
- func Float64bits(f float64) uint64 // float64 和 uint64 的转换
59-
- func Float64frombits(b uint64) float64 // uint64 和 float64 的转换
57+
58+
- func Float32bits(f float32) uint32 // float32 和 unit32 的转换
59+
- func Float32frombits(b uint32) float32 // uint32 和 float32 的转换
60+
- func Float64bits(f float64) uint64 // float64 和 uint64 的转换
61+
- func Float64frombits(b uint64) float64 // uint64 和 float64 的转换
6062

6163
## 5.1.5 其他函数 ##
6264

63-
- func Abs(x float64) float64 // 绝对值函数
64-
- func Ceil(x float64) float64 // 向上取整
65-
- func Floor(x float64) float64 // 向下取整
66-
- func Mod(x, y float64) float64 // 取模
67-
- func Modf(f float64) (int float64, frac float64) // 分解 f,以得到 f 的整数和小数部分
68-
- func Frexp(f float64) (frac float64, exp int) // 分解 f,得到 f 的位数和指数
69-
- func Max(x, y float64) float64 // 取大值
70-
- func Min(x, y float64) float64 // 取小值
71-
- func Dim(x, y float64) float64 // 复数的维数
72-
- func J0(x float64) float64 // 0 阶贝塞尔函数
73-
- func J1(x float64) float64 // 1 阶贝塞尔函数
74-
- func Jn(n int, x float64) float64 // n 阶贝塞尔函数
75-
- func Y0(x float64) float64 // 第二类贝塞尔函数 0 阶
76-
- func Y1(x float64) float64 // 第二类贝塞尔函数 1 阶
77-
- func Yn(n int, x float64) float64 // 第二类贝塞尔函数 n 阶
78-
- func Erf(x float64) float64 // 误差函数
79-
- func Erfc(x float64) float64 // 余补误差函数
80-
- func Copysign(x, y float64) float64 // 以 y 的符号返回 x 值
81-
- func Signbit(x float64) bool // 获取 x 的符号
82-
- func Gamma(x float64) float64 // 伽玛函数
83-
- func Lgamma(x float64) (lgamma float64, sign int) // 伽玛函数的自然对数
84-
- func Ldexp(frac float64, exp int) float64 // value 乘以 2 的 exp 次幂
85-
- func Nextafter(x, y float64) (r float64) // 返回参数 x 在参数 y 方向上可以表示的最接近的数值,若 x 等于 y,则返回 x
86-
- func Nextafter32(x, y float32) (r float32) // 返回参数 x 在参数 y 方向上可以表示的最接近的数值,若 x 等于 y,则返回 x
87-
- func Remainder(x, y float64) float64 // 取余运算
88-
- func Trunc(x float64) float64 // 截取函数
65+
- func Abs(x float64) float64 // 绝对值函数
66+
- func Ceil(x float64) float64 // 向上取整
67+
- func Floor(x float64) float64 // 向下取整
68+
- func Mod(x, y float64) float64 // 取模
69+
- func Modf(f float64) (int float64, frac float64) // 分解 f,以得到 f 的整数和小数部分
70+
- func Frexp(f float64) (frac float64, exp int) // 分解 f,得到 f 的位数和指数
71+
- func Max(x, y float64) float64 // 取大值
72+
- func Min(x, y float64) float64 // 取小值
73+
- func Dim(x, y float64) float64 // 复数的维数
74+
- func J0(x float64) float64 // 0 阶贝塞尔函数
75+
- func J1(x float64) float64 // 1 阶贝塞尔函数
76+
- func Jn(n int, x float64) float64 // n 阶贝塞尔函数
77+
- func Y0(x float64) float64 // 第二类贝塞尔函数 0 阶
78+
- func Y1(x float64) float64 // 第二类贝塞尔函数 1 阶
79+
- func Yn(n int, x float64) float64 // 第二类贝塞尔函数 n 阶
80+
- func Erf(x float64) float64 // 误差函数
81+
- func Erfc(x float64) float64 // 余补误差函数
82+
- func Copysign(x, y float64) float64 // 以 y 的符号返回 x 值
83+
- func Signbit(x float64) bool // 获取 x 的符号
84+
- func Gamma(x float64) float64 // 伽玛函数
85+
- func Lgamma(x float64) (lgamma float64, sign int) // 伽玛函数的自然对数
86+
- func Ldexp(frac float64, exp int) float64 // value 乘以 2 的 exp 次幂
87+
- func Nextafter(x, y float64) (r float64) // 返回参数 x 在参数 y 方向上可以表示的最接近的数值,若 x 等于 y,则返回 x
88+
- func Nextafter32(x, y float32) (r float32) // 返回参数 x 在参数 y 方向上可以表示的最接近的数值,若 x 等于 y,则返回 x
89+
- func Remainder(x, y float64) float64 // 取余运算
90+
- func Trunc(x float64) float64 // 截取函数
8991

9092
# 导航 #

0 commit comments

Comments
 (0)
Please sign in to comment.