mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-23 19:10:28 +00:00
refactor: repositories (#28)
* cleanup unnecessary mocks * refactor document storage location * remove unused function * move ownership to document types to repo package * move types and mappers to repo package * refactor sets to own package
This commit is contained in:
parent
2e82398e5c
commit
343290a55a
79 changed files with 3169 additions and 3160 deletions
56
backend/pkgs/set/set.go
Normal file
56
backend/pkgs/set/set.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package set
|
||||
|
||||
type key interface {
|
||||
comparable
|
||||
}
|
||||
|
||||
type Set[T key] struct {
|
||||
mp map[T]struct{}
|
||||
}
|
||||
|
||||
func New[T key](v ...T) Set[T] {
|
||||
mp := make(map[T]struct{}, len(v))
|
||||
|
||||
s := Set[T]{mp}
|
||||
|
||||
s.Insert(v...)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Set[T]) Insert(v ...T) {
|
||||
for _, e := range v {
|
||||
s.mp[e] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (s Set[T]) Remove(v ...T) {
|
||||
for _, e := range v {
|
||||
delete(s.mp, e)
|
||||
}
|
||||
}
|
||||
|
||||
func (s Set[T]) Contains(v T) bool {
|
||||
_, ok := s.mp[v]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s Set[T]) ContainsAll(v ...T) bool {
|
||||
for _, e := range v {
|
||||
if !s.Contains(e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s Set[T]) Slice() []T {
|
||||
slice := make([]T, 0, len(s.mp))
|
||||
for k := range s.mp {
|
||||
slice = append(slice, k)
|
||||
}
|
||||
return slice
|
||||
}
|
||||
|
||||
func (s Set[T]) Len() int {
|
||||
return len(s.mp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue