-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
49 lines (43 loc) · 826 Bytes
/
util.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
package util
import (
"math/rand"
"sort"
"time"
)
func OnlyOneNotNil(items ...interface{}) (any bool, one bool) {
oneNotNil := false
for _, i := range items {
if i != nil {
if oneNotNil {
return true, false
}
oneNotNil = true
}
}
return oneNotNil, oneNotNil
}
func EqualUnsorted(s1 []string, s2 []string) bool {
if len(s1) != len(s2) {
return false
}
s1_2, s2_2 := make([]string, len(s1)), make([]string, len(s2))
sort.Strings(s1)
sort.Strings(s2)
for i, s := range s1_2 {
if s != s2_2[i] {
return false
}
}
return true
}
func init() {
rand.Seed(time.Now().UnixNano())
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz")
func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}