mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [chore] Migrate to golangci-lint v2 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issue Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Add more package comments. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix golangci-lint config and the remaining checks Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Use Go 1.24 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix container builds Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix more failing tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix test failure Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix another len assertion Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Move location tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most remaining lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Only run XDG specific tests on linux Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Attempt to address on source of flaky failures Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
45 lines
923 B
Go
45 lines
923 B
Go
// Package diff implements diffing of two lists.
|
|
package diff
|
|
|
|
// Stat returnes the number of items added to and removed from the first to
|
|
// the second list.
|
|
func Stat[K comparable](l, r []K) (int, int) {
|
|
added, removed := List(l, r)
|
|
|
|
return len(added), len(removed)
|
|
}
|
|
|
|
// List returns two lists, the first one contains the items that were added from left
|
|
// to right, the second one contains the items that were removed from left to right.
|
|
func List[K comparable](l, r []K) ([]K, []K) {
|
|
ml := listToMap(l)
|
|
mr := listToMap(r)
|
|
|
|
var added []K
|
|
|
|
for k := range mr {
|
|
if _, found := ml[k]; !found {
|
|
added = append(added, k)
|
|
}
|
|
}
|
|
|
|
var removed []K
|
|
|
|
for k := range ml {
|
|
if _, found := mr[k]; !found {
|
|
removed = append(removed, k)
|
|
}
|
|
}
|
|
|
|
return added, removed
|
|
}
|
|
|
|
func listToMap[K comparable](l []K) map[K]struct{} {
|
|
m := make(map[K]struct{}, len(l))
|
|
for _, e := range l {
|
|
m[e] = struct{}{}
|
|
}
|
|
|
|
return m
|
|
}
|