mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-25 12:00:29 +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
101
backend/pkgs/set/funcs.go
Normal file
101
backend/pkgs/set/funcs.go
Normal file
|
@ -0,0 +1,101 @@
|
|||
package set
|
||||
|
||||
// Diff returns the difference between two sets
|
||||
func Diff[T key](a, b Set[T]) Set[T] {
|
||||
s := New[T]()
|
||||
for k := range a.mp {
|
||||
if !b.Contains(k) {
|
||||
s.Insert(k)
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Intersect returns the intersection between two sets
|
||||
func Intersect[T key](a, b Set[T]) Set[T] {
|
||||
s := New[T]()
|
||||
for k := range a.mp {
|
||||
if b.Contains(k) {
|
||||
s.Insert(k)
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Union returns the union between two sets
|
||||
func Union[T key](a, b Set[T]) Set[T] {
|
||||
s := New[T]()
|
||||
for k := range a.mp {
|
||||
s.Insert(k)
|
||||
}
|
||||
for k := range b.mp {
|
||||
s.Insert(k)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Xor returns the symmetric difference between two sets
|
||||
func Xor[T key](a, b Set[T]) Set[T] {
|
||||
s := New[T]()
|
||||
for k := range a.mp {
|
||||
if !b.Contains(k) {
|
||||
s.Insert(k)
|
||||
}
|
||||
}
|
||||
for k := range b.mp {
|
||||
if !a.Contains(k) {
|
||||
s.Insert(k)
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Equal returns true if two sets are equal
|
||||
func Equal[T key](a, b Set[T]) bool {
|
||||
if a.Len() != b.Len() {
|
||||
return false
|
||||
}
|
||||
for k := range a.mp {
|
||||
if !b.Contains(k) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Subset returns true if a is a subset of b
|
||||
func Subset[T key](a, b Set[T]) bool {
|
||||
if a.Len() > b.Len() {
|
||||
return false
|
||||
}
|
||||
for k := range a.mp {
|
||||
if !b.Contains(k) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Superset returns true if a is a superset of b
|
||||
func Superset[T key](a, b Set[T]) bool {
|
||||
if a.Len() < b.Len() {
|
||||
return false
|
||||
}
|
||||
for k := range b.mp {
|
||||
if !a.Contains(k) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Disjoint returns true if two sets are disjoint
|
||||
func Disjoint[T key](a, b Set[T]) bool {
|
||||
for k := range a.mp {
|
||||
if b.Contains(k) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue