chore: cleanup and add tools
This commit is contained in:
12
set.go
12
set.go
@@ -2,22 +2,22 @@ package aoc
|
||||
|
||||
import "golang.org/x/exp/maps"
|
||||
|
||||
type set[T comparable] map[T]struct{}
|
||||
type Set[T comparable] map[T]struct{}
|
||||
|
||||
func Set[T comparable](arr ...T) set[T] {
|
||||
m := make(set[T], len(arr))
|
||||
func NewSet[T comparable](arr ...T) Set[T] {
|
||||
m := make(Set[T], len(arr))
|
||||
for _, a := range arr {
|
||||
m[a] = struct{}{}
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (m *set[T]) Add(a T) {
|
||||
func (m *Set[T]) Add(a T) {
|
||||
(*m)[a] = struct{}{}
|
||||
}
|
||||
func (m *set[T]) Items() []T {
|
||||
func (m *Set[T]) Items() []T {
|
||||
return maps.Keys(*m)
|
||||
}
|
||||
func (m *set[T]) Has(a T) bool {
|
||||
func (m *Set[T]) Has(a T) bool {
|
||||
var ok bool
|
||||
_, ok = (*m)[a]
|
||||
return ok
|
||||
|
||||
Reference in New Issue
Block a user