```
feat(slice): 添加切片详细示例和图片资源 - 在README.md中添加image-2.png、image-3.png、image-4.png图片引用, 用于说明切片操作的可视化内容 - 将"通过切片创建新的切片"章节内容重新排序至切片拷贝部分之后 - 在main.go中增加多种切片声明方式的代码示例 - 补充切片访问、遍历、引用类型特性、深拷贝等完整示例 - 添加append.drawio和ref.drawio绘图文件,提供切片操作流程图 ```
This commit is contained in:
parent
2368215c68
commit
277c5dd15c
@ -118,22 +118,7 @@ s = append(s, 4, 5)
|
|||||||
fmt.Println(s) // [1 2 3 4 5]
|
fmt.Println(s) // [1 2 3 4 5]
|
||||||
```
|
```
|
||||||
|
|
||||||
## 通过切片创建新的切片
|

|
||||||
|
|
||||||
**原理**:切片操作创建新的切片视图,共享底层数组。新切片的长度是high-low,容量是原容量减去low。
|
|
||||||
|
|
||||||
```go
|
|
||||||
s := []int{0, 1, 2, 3, 4, 5}
|
|
||||||
|
|
||||||
// 创建子切片:s[low:high] (不包括high)
|
|
||||||
sub1 := s[1:4] // [1, 2, 3]
|
|
||||||
fmt.Println(sub1)
|
|
||||||
|
|
||||||
// 省略索引
|
|
||||||
sub2 := s[:3] // [0, 1, 2]
|
|
||||||
sub3 := s[2:] // [2, 3, 4, 5]
|
|
||||||
sub4 := s[:] // [0, 1, 2, 3, 4, 5] 复制整个切片
|
|
||||||
```
|
|
||||||
|
|
||||||
## 遍历切片
|
## 遍历切片
|
||||||
|
|
||||||
@ -166,6 +151,9 @@ fmt.Println(s1) // [99 2 3] s1 也被修改了
|
|||||||
fmt.Println(s2) // [99 2 3]
|
fmt.Println(s2) // [99 2 3]
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
## 切片拷贝
|
## 切片拷贝
|
||||||
|
|
||||||
**原理**:使用copy函数进行深拷贝,创建独立的数据副本。修改拷贝后的切片不会影响原切片。
|
**原理**:使用copy函数进行深拷贝,创建独立的数据副本。修改拷贝后的切片不会影响原切片。
|
||||||
@ -180,6 +168,25 @@ fmt.Println(s1) // [1 2 3] s1 不变
|
|||||||
fmt.Println(s2) // [99 2 3]
|
fmt.Println(s2) // [99 2 3]
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 通过切片创建新的切片
|
||||||
|
|
||||||
|
**原理**:切片操作创建新的切片视图,共享底层数组。新切片的长度是high-low,容量是原容量减去low。
|
||||||
|
|
||||||
|
```go
|
||||||
|
s := []int{0, 1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
// 创建子切片:s[low:high] (不包括high)
|
||||||
|
sub1 := s[1:4] // [1, 2, 3]
|
||||||
|
fmt.Println(sub1)
|
||||||
|
|
||||||
|
// 省略索引
|
||||||
|
sub2 := s[:3] // [0, 1, 2]
|
||||||
|
sub3 := s[2:] // [2, 3, 4, 5]
|
||||||
|
sub4 := s[:] // [0, 1, 2, 3, 4, 5] 复制整个切片
|
||||||
|
```
|
||||||
|
|
||||||
## 切片作为函数参数
|
## 切片作为函数参数
|
||||||
|
|
||||||
**原理**:切片作为参数传递时,是引用传递,函数内修改会影响调用者。高效但需注意副作用。
|
**原理**:切片作为参数传递时,是引用传递,函数内修改会影响调用者。高效但需注意副作用。
|
||||||
|
|||||||
128
day02/slice/append.drawio
Normal file
128
day02/slice/append.drawio
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<mxfile host="65bd71144e">
|
||||||
|
<diagram id="g4mhtEkjE2LYKTrqnUZr" name="第 1 页">
|
||||||
|
<mxGraphModel dx="1134" dy="414" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||||
|
<root>
|
||||||
|
<mxCell id="0"/>
|
||||||
|
<mxCell id="1" parent="0"/>
|
||||||
|
<mxCell id="2" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="160" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="3" value="s1: []int{1,2,3}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="130" width="110" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="4" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="120" y="185" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="5" value="len(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="230" y="185" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="6" value="cap(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="350" y="185" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="7" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="300" width="370" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="8" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.203;entryY=0.017;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="4" target="7">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="9" value="1" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="120" y="310" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="10" value="2" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="230" y="310" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="11" value="3" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="334" y="310" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="12" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="430" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="13" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="120" y="455" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="14" value="len(4)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="230" y="455" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="15" value="cap(6)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="350" y="455" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="16" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="570" width="620" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="17" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="13">
|
||||||
|
<mxGeometry relative="1" as="geometry">
|
||||||
|
<mxPoint x="160" y="570" as="targetPoint"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="18" value="1" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="120" y="580" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="19" value="2" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="220" y="580" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="20" value="3" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="320" y="580" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="21" value="s1_v1:= append(s1, 4)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="400" width="140" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="22" value="arr1: [3]int" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="270" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="23" value="4" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="414" y="580" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="27" value="arr2: [6]int" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="540" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="28" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="710" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="29" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="120" y="735" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="30" value="len(5)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="230" y="735" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="31" value="cap(6)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="350" y="735" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="32" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="850" width="620" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="33" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="29">
|
||||||
|
<mxGeometry relative="1" as="geometry">
|
||||||
|
<mxPoint x="160" y="850" as="targetPoint"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="34" value="1" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="120" y="860" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="35" value="2" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="220" y="860" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="36" value="3" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="320" y="860" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="37" value="s1_v2:= append(s1, 5)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="680" width="140" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="38" value="4" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="414" y="860" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="39" value="arr2: [6]int" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="90" y="820" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="40" value="5" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="520" y="860" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="41" value="容量不够,底层数组扩容,重新申请内存" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="240" y="400" width="230" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="42" value="容量够,继续使用底层数组进行数据存储" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="240" y="680" width="230" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
</root>
|
||||||
|
</mxGraphModel>
|
||||||
|
</diagram>
|
||||||
|
</mxfile>
|
||||||
BIN
day02/slice/image-2.png
Normal file
BIN
day02/slice/image-2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
BIN
day02/slice/image-3.png
Normal file
BIN
day02/slice/image-3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
day02/slice/image-4.png
Normal file
BIN
day02/slice/image-4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
@ -3,8 +3,12 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
/*
|
||||||
|
声明与赋值
|
||||||
|
*/
|
||||||
// 1. 声明切片, 切片不是一个值,是一个boxed结构体, array unsafe.Pointer // 数组指针
|
// 1. 声明切片, 切片不是一个值,是一个boxed结构体, array unsafe.Pointer // 数组指针
|
||||||
// 底层数组的长度: 容量10, 当前有几个元素3
|
// 底层数组的长度: 容量10, 当前有几个元素3
|
||||||
|
// 需要考虑性能时,这个常用
|
||||||
slice1 := make([]int, 3, 5)
|
slice1 := make([]int, 3, 5)
|
||||||
fmt.Println(slice1, len(slice1), cap(slice1))
|
fmt.Println(slice1, len(slice1), cap(slice1))
|
||||||
// 底层数组的长度: 容量10, 当前有几个元素3
|
// 底层数组的长度: 容量10, 当前有几个元素3
|
||||||
@ -14,4 +18,96 @@ func main() {
|
|||||||
// 扩容: 一般是原来的2倍, 新申请一块更大的数组, 把老数据copy过去
|
// 扩容: 一般是原来的2倍, 新申请一块更大的数组, 把老数据copy过去
|
||||||
slice1 = append(slice1, 6)
|
slice1 = append(slice1, 6)
|
||||||
fmt.Println(slice1, len(slice1), cap(slice1))
|
fmt.Println(slice1, len(slice1), cap(slice1))
|
||||||
|
|
||||||
|
// 2. 声明并赋值 (不常用)
|
||||||
|
var slice2 []int
|
||||||
|
slice2 = []int{1, 2, 3, 4, 5}
|
||||||
|
fmt.Println(slice2, len(slice2), cap(slice2))
|
||||||
|
|
||||||
|
// 3. 声明赋值放在一起 (常用)
|
||||||
|
var slice3 []int = []int{1, 2, 3, 4, 5}
|
||||||
|
fmt.Println(slice3, len(slice3), cap(slice3))
|
||||||
|
|
||||||
|
// 4. 快捷声明赋值 (常用)
|
||||||
|
slice4 := []int{1, 2, 3, 4, 5}
|
||||||
|
fmt.Println(slice4, len(slice4), cap(slice4))
|
||||||
|
|
||||||
|
/*
|
||||||
|
切片的访问
|
||||||
|
1. 通过下标(元素的索引)访问切片元素
|
||||||
|
2. 元素值修改,直接通过下标赋值即可
|
||||||
|
*/
|
||||||
|
fmt.Println("slice4[0]=", slice4[0])
|
||||||
|
slice4[0] = 100
|
||||||
|
fmt.Println("slice4[0]=", slice4[0])
|
||||||
|
|
||||||
|
/*
|
||||||
|
切片中添加元素
|
||||||
|
append(切片变量, 元素1, 元素2, ...)
|
||||||
|
注意append 后 是参数一个新的切片变量, 所以要接收返回值
|
||||||
|
动作: 申请了新的底层数组, 把老数据copy过去, 然后添加新的元素
|
||||||
|
append的元素如果超过容器,会触发地址扩容, 新的数组
|
||||||
|
*/
|
||||||
|
slice4_v2 := append(slice4, 6, 7, 8)
|
||||||
|
fmt.Println("slice4:", slice4, len(slice4), cap(slice4))
|
||||||
|
fmt.Println("slice4_v2:", slice4_v2, len(slice4_v2), cap(slice4_v2))
|
||||||
|
|
||||||
|
/*
|
||||||
|
1. nil 切片: 没有分配内存(array指针是nil), 长度和容量都是0
|
||||||
|
2. 空切片
|
||||||
|
切片时一个应用类型(盒子)
|
||||||
|
*/
|
||||||
|
var slice5 []int // nil 切片
|
||||||
|
fmt.Println(slice5, len(slice5), cap(slice5))
|
||||||
|
slice5 = append(slice5, 10, 11, 12)
|
||||||
|
fmt.Println(slice5, len(slice5), cap(slice5))
|
||||||
|
|
||||||
|
slice6 := []int{} // 空切片
|
||||||
|
fmt.Println(slice6, len(slice6), cap(slice6))
|
||||||
|
slice6 = append(slice6, 10)
|
||||||
|
fmt.Println(slice6, len(slice6), cap(slice6))
|
||||||
|
|
||||||
|
/*
|
||||||
|
切片的遍历
|
||||||
|
1. for 循环遍历, 实际上遍历的也是底层的数组
|
||||||
|
2. for range 遍历
|
||||||
|
*/
|
||||||
|
fmt.Println("== 切片的遍历: for ==")
|
||||||
|
for i := 0; i < len(slice4_v2); i++ {
|
||||||
|
fmt.Printf("slice4_v2[%d]=%d\n", i, slice4_v2[i])
|
||||||
|
}
|
||||||
|
fmt.Println("== 切片的遍历: for range (推荐) ==")
|
||||||
|
for index, value := range slice4_v2 {
|
||||||
|
fmt.Printf("slice4_v2[%d]=%d\n", index, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
切片是一种引用类型
|
||||||
|
注意: 数组是引用类型吗? 不是
|
||||||
|
1. 如果是数组: 是2块隔离的内存地址空间(线性分配)
|
||||||
|
2. 如果是切片: 底层数组是同一块内存地址空间
|
||||||
|
浅拷贝: 赋值 底层数据没有copy一份, 还是指向同一块内存地址空间
|
||||||
|
*/
|
||||||
|
fmt.Println("== 切片是一种引用类型 ==")
|
||||||
|
slice7 := []int{1, 2, 3}
|
||||||
|
slice8 := slice7
|
||||||
|
fmt.Println("slice7:", slice7)
|
||||||
|
fmt.Println("slice8:", slice8)
|
||||||
|
slice8[0] = 1000
|
||||||
|
fmt.Println("slice7:", slice7)
|
||||||
|
fmt.Println("slice8:", slice8)
|
||||||
|
|
||||||
|
/*
|
||||||
|
切片的拷贝
|
||||||
|
如果希望把 底层arry里面的数据copy到另一个切片中
|
||||||
|
使用内置函数: copy(目标切片, 源切片)
|
||||||
|
深拷贝: 底层数据已copy一份 申请一片新的内存来存储这个值
|
||||||
|
*/
|
||||||
|
fmt.Println("== 切片的拷贝 ==")
|
||||||
|
slice9 := make([]int, len(slice7))
|
||||||
|
copy(slice9, slice7)
|
||||||
|
fmt.Println("slice9:", slice9)
|
||||||
|
slice9[0] = 2000
|
||||||
|
fmt.Println("slice7:", slice7)
|
||||||
|
fmt.Println("slice9:", slice9)
|
||||||
}
|
}
|
||||||
|
|||||||
165
day02/slice/ref.drawio
Normal file
165
day02/slice/ref.drawio
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<mxfile host="65bd71144e">
|
||||||
|
<diagram id="GDfFOCQBjgRLaX9kyX6L" name="第 1 页">
|
||||||
|
<mxGraphModel dx="1134" dy="596" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||||
|
<root>
|
||||||
|
<mxCell id="0"/>
|
||||||
|
<mxCell id="1" parent="0"/>
|
||||||
|
<mxCell id="25" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="14">
|
||||||
|
<mxGeometry relative="1" as="geometry">
|
||||||
|
<Array as="points">
|
||||||
|
<mxPoint x="60" y="160"/>
|
||||||
|
<mxPoint x="60" y="440"/>
|
||||||
|
</Array>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="26" value="赋值: s2 := s1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="25">
|
||||||
|
<mxGeometry x="0.0414" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="3" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="200" y="120" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="4" value="s1: []int{1,2,3}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="200" y="90" width="110" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="5" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="230" y="145" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="6" value="len(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="340" y="145" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="7" value="cap(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="460" y="145" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="8" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="200" y="260" width="370" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="9" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.203;entryY=0.017;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="5" target="8">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="10" value="1 -&gt; 1000" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="230" y="270" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="11" value="2" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="340" y="270" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="12" value="3" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="444" y="270" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="13" value="arr1: [3]int" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="200" y="230" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="14" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="195" y="400" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="15" value="s2: []int{1,2,3}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="195" y="370" width="110" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="16" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="225" y="425" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="17" value="len(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="335" y="425" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="18" value="cap(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="455" y="425" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="28" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.2;entryY=0.983;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="15" target="8">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="29" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="167.5" y="510" width="30" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="30" value="s2[0] = 1000" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="222.5" y="525" width="160" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="31" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="33" target="44">
|
||||||
|
<mxGeometry relative="1" as="geometry">
|
||||||
|
<Array as="points">
|
||||||
|
<mxPoint x="55" y="720"/>
|
||||||
|
<mxPoint x="55" y="1000"/>
|
||||||
|
</Array>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="32" value="赋值: copy(s2, s1)" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="31">
|
||||||
|
<mxGeometry x="0.0414" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="33" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="195" y="680" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="34" value="s1: []int{1,2,3}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="195" y="650" width="110" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="35" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="225" y="705" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="36" value="len(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="335" y="705" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="37" value="cap(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="455" y="705" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="38" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="195" y="820" width="370" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="39" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.203;entryY=0.017;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="35" target="38">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="40" value="1" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="225" y="830" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="41" value="2" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="335" y="830" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="42" value="3" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="439" y="830" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="43" value="arr1: [3]int" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="195" y="790" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="44" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="960" width="370" height="80" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="45" value="s2: []int{1,2,3}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="930" width="110" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="46" value="arry ptr" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="220" y="985" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="47" value="len(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="330" y="985" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="48" value="cap(3)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="450" y="985" width="90" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="50" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="40" y="1070" width="30" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="51" value="s2[0] = 1000" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="60" y="1085" width="160" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="52" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="1109" width="370" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="53" value="1 -&gt; 1000" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="220" y="1119" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="54" value="2" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="330" y="1119" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="55" value="3" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="434" y="1119" width="80" height="40" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="56" value="arr2: [3]int" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="1079" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="58" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.195;entryY=-0.017;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="46" target="52">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
</root>
|
||||||
|
</mxGraphModel>
|
||||||
|
</diagram>
|
||||||
|
</mxfile>
|
||||||
Loading…
x
Reference in New Issue
Block a user