Raspberry Pi alarm clock server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
853 B

package sonar
import "strconv"
// Set is a lookup set of strings.
type Set map[string]interface{}
// NewSet makes a new Set from a list of strings.
func NewSet(input []string) Set {
set := Set{}
for _, v := range input {
set[v] = nil
}
return set
}
// In queries if the value is in the set.
func (s Set) In(v string) bool {
_, ok := s[v]
return ok
}
// SliceToSet makes a slice into a set map.
func SliceToSet(slice []string) map[string]bool {
var result = make(map[string]bool)
for _, v := range slice {
result[v] = true
}
return result
}
// Str2IntSlice converts a string slice to an int slice.
func Str2IntSlice(str []string) ([]int, error) {
result := make([]int, len(str))
for i, literal := range str {
val, err := strconv.Atoi(literal)
if err != nil {
return result, err
}
result[i] = val
}
return result, nil
}