-
Notifications
You must be signed in to change notification settings - Fork 111
/
slices.go
75 lines (59 loc) · 1.24 KB
/
slices.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2017 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package slices
import (
"fmt"
"math/cmplx"
)
func IntSum(s []int) int {
sum := 0
for _, value := range s {
sum += value
}
return sum
}
func CreateSlice() []int {
return []int{1, 2, 3, 4}
}
type SliceUint8 []uint8
type SliceUint16 []uint16
type SliceUint32 []uint32
type SliceUint64 []uint64
type SliceInt8 []int8
type SliceInt16 []int16
type SliceInt32 []int32
type SliceInt64 []int64
type SliceComplex []complex128
type SliceIface []interface{}
type S struct {
Name string
}
func CreateSSlice() []*S {
return []*S{&S{"S0"}, &S{"S1"}, &S{"S2"}}
}
func PrintSSlice(ss []*S) {
for i, s := range ss {
fmt.Printf("%d: %v\n", i, s.Name)
}
}
func PrintS(s *S) {
fmt.Printf("%v\n", s.Name)
}
func CmplxSqrt(arr SliceComplex) SliceComplex {
res := make([]complex128, len(arr))
for i, el := range arr {
res[i] = cmplx.Sqrt(el)
}
return res
}
func GetEmptyMatrix(xSize int, ySize int) [][]bool {
result := [][]bool{}
for i := 0; i < xSize; i++ {
result = append(result, []bool{})
for j := 0; j < ySize; j++ {
result[i] = append(result[i], false)
}
}
return result
}