-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetExtend.go
More file actions
66 lines (59 loc) · 1.22 KB
/
setExtend.go
File metadata and controls
66 lines (59 loc) · 1.22 KB
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
// Contains extend and fromSlice methods
package simpleset
// ExtendString adds values from a string slice to set.
func (s *Set) ExtendString(v []string) error {
var err error
if len(v) > 0 {
err = s.checkType(v[0])
if err == nil {
for _, i := range v {
s.s[i] = false
}
}
}
return err
}
// FromStringSlice returns a new set from a string slice.
func FromStringSlice(v []string) *Set {
ret := NewStringSet()
ret.ExtendString(v)
return ret
}
// ExtendInt adds values from an int slice to set.
func (s *Set) ExtendInt(v []int) error {
var err error
if len(v) > 0 {
err = s.checkType(v[0])
if err == nil {
for _, i := range v {
s.i[i] = false
}
}
}
return err
}
// FromIntSlice returns a new set from a string slice.
func FromIntSlice(v []int) *Set {
ret := NewIntSet()
ret.ExtendInt(v)
return ret
}
// ExtendFloat adds values from a float64 slice to set.
func (s *Set) ExtendFloat(v []float64) error {
var err error
if len(v) > 0 {
err = s.checkType(v[0])
if err == nil {
for _, i := range v {
s.f[i] = false
}
}
}
return err
}
// FromFloatSlice returns a new set from a float64 slice.
func FromFloatSlice(v []float64) *Set {
ret := NewFloatSet()
ret.ExtendFloat(v)
return ret
}