Simplify removeDuplicates
Use a sort+compact construct instead of doing it by hand with a hashmap. The time complexity is now O(nlogn+n) instead of O(n), and space complexity around O(logn) instead of O(n+uniq(n)), but it shouldn't matter anyway, since removeDuplicates is only called to deduplicate tags.
This commit is contained in:
parent
91f5522ce0
commit
863a5b3648
1 changed files with 4 additions and 11 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"miniflux.app/v2/internal/crypto"
|
"miniflux.app/v2/internal/crypto"
|
||||||
|
@ -615,15 +616,7 @@ func (s *Storage) UnshareEntry(userID int64, entryID int64) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeDuplicate removes duplicate entries from a slice
|
func removeDuplicates(l []string) []string {
|
||||||
func removeDuplicates[T string | int](sliceList []T) []T {
|
slices.Sort(l)
|
||||||
allKeys := make(map[T]bool)
|
return slices.Compact(l)
|
||||||
list := []T{}
|
|
||||||
for _, item := range sliceList {
|
|
||||||
if _, value := allKeys[item]; !value {
|
|
||||||
allKeys[item] = true
|
|
||||||
list = append(list, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue