-
Notifications
You must be signed in to change notification settings - Fork 1
/
unique.go
161 lines (146 loc) · 3.17 KB
/
unique.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package g
import "time"
func UniqBool(input []bool) []bool {
output := make([]bool, 0, 2)
counter := 0
for i := range input {
if counter == 3 {
return output
}
if input[i] {
counter = counter | 1
} else {
counter = counter | 2
}
if !BoolInSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqString(input []string) []string {
output := make([]string, 0, len(input))
for i := range input {
if !StringInSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqInt(input []int) []int {
output := make([]int, 0, len(input))
for i := range input {
if !IntInSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqInt8(input []int8) []int8 {
output := make([]int8, 0, len(input))
for i := range input {
if !Int8InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqInt16(input []int16) []int16 {
output := make([]int16, 0, len(input))
for i := range input {
if !Int16InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqInt32(input []int32) []int32 {
output := make([]int32, 0, len(input))
for i := range input {
if !Int32InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqInt64(input []int64) []int64 {
output := make([]int64, 0, len(input))
for i := range input {
if !Int64InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqUint(input []uint) []uint {
output := make([]uint, 0, len(input))
for i := range input {
if !UintInSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqUint8(input []uint8) []uint8 {
output := make([]uint8, 0, len(input))
for i := range input {
if !Uint8InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqUint16(input []uint16) []uint16 {
output := make([]uint16, 0, len(input))
for i := range input {
if !Uint16InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqUint32(input []uint32) []uint32 {
output := make([]uint32, 0, len(input))
for i := range input {
if !Uint32InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqUint64(input []uint64) []uint64 {
output := make([]uint64, 0, len(input))
for i := range input {
if !Uint64InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqFloat32(input []float32) []float32 {
output := make([]float32, 0, len(input))
for i := range input {
if !Float32InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqFloat64(input []float64) []float64 {
output := make([]float64, 0, len(input))
for i := range input {
if !Float64InSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}
func UniqTime(input []time.Time) []time.Time {
output := make([]time.Time, 0, len(input))
for i := range input {
if !TimeInSlice(input[i], output) {
output = append(output, input[i])
}
}
return output
}