|
@@ -0,0 +1,86 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import "fmt"
|
|
|
+
|
|
|
+func main() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var buf0 []int
|
|
|
+ buf1 := []int{}
|
|
|
+ buf2 := []int{42}
|
|
|
+ buf3 := make([]int, 0)
|
|
|
+ buf4 := make([]int, 5)
|
|
|
+ buf5 := make([]int, 5, 10)
|
|
|
+
|
|
|
+ fmt.Println(buf0, buf1, buf2, buf3, buf4, buf5)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ someInt := buf2[0]
|
|
|
+ fmt.Println(someInt)
|
|
|
+
|
|
|
+
|
|
|
+ var buf []int
|
|
|
+ buf = append(buf, 9, 10)
|
|
|
+ buf = append(buf, 12)
|
|
|
+
|
|
|
+
|
|
|
+ otherBuf := make([]int, 3)
|
|
|
+ buf = append(buf, otherBuf...)
|
|
|
+
|
|
|
+ fmt.Println(buf, otherBuf)
|
|
|
+
|
|
|
+
|
|
|
+ var bufLen, bufCap int = len(buf), cap(buf)
|
|
|
+
|
|
|
+ fmt.Println(bufLen, bufCap)
|
|
|
+
|
|
|
+ test1()
|
|
|
+}
|
|
|
+
|
|
|
+func test1() {
|
|
|
+
|
|
|
+ sl1 := buf[1:4]
|
|
|
+ sl2 := buf[:2]
|
|
|
+ sl3 := buf[2:]
|
|
|
+ fmt.Println(sl1, sl2, sl3)
|
|
|
+
|
|
|
+
|
|
|
+ newBuf := buf[:]
|
|
|
+
|
|
|
+
|
|
|
+ newBuf[0] = 9
|
|
|
+
|
|
|
+
|
|
|
+ newBuf = append(newBuf, 6)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ newBuf[0] = 1
|
|
|
+ fmt.Println("buf", buf)
|
|
|
+ fmt.Println("newBuf", newBuf)
|
|
|
+
|
|
|
+
|
|
|
+ var emptyBuf []int
|
|
|
+
|
|
|
+ copied := copy(emptyBuf, buf)
|
|
|
+ fmt.Println(copied, emptyBuf)
|
|
|
+
|
|
|
+
|
|
|
+ newBuf = make([]int, len(buf), len(buf))
|
|
|
+ copy(newBuf, buf)
|
|
|
+ fmt.Println(newBuf)
|
|
|
+
|
|
|
+
|
|
|
+ ints := []int{1, 2, 3, 4}
|
|
|
+ copy(ints[1:3], []int{5, 6})
|
|
|
+ fmt.Println(ints)
|
|
|
+}
|