Files
alfred-be/alfred/utils/data_structure_utils.go

35 lines
531 B
Go
Raw Permalink Normal View History

2026-03-08 16:14:42 +05:30
package utils
import "sort"
type Set map[string]bool
func (s Set) Add(element string) {
s[element] = true
}
func (s Set) Remove(element string) {
delete(s, element)
}
func (s Set) Contains(element string) bool {
return s[element]
}
func (s Set) Size() int {
return len(s)
}
func (s Set) Elements() []string {
elements := make([]string, 0, len(s))
for element := range s {
elements = append(elements, element)
}
sort.Slice(elements, func(i, j int) bool {
return elements[i] < elements[j]
})
return elements
}