mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-10-25 06:33:09 +00:00
Use stdlib maps/slices
This commit is contained in:
parent
e7ed5716a9
commit
405f5ce148
27 changed files with 55 additions and 60 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -23,7 +24,6 @@ import (
|
|||
|
||||
"github.com/edwvee/exiffix"
|
||||
"github.com/kovidgoyal/imaging"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import (
|
|||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
|
|
|||
|
|
@ -4,12 +4,26 @@ package utils
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
|
||||
r := make([]K, 0, len(m))
|
||||
for k := range m {
|
||||
r = append(r, k)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func Values[M ~map[K]V, K comparable, V any](m M) []V {
|
||||
r := make([]V, 0, len(m))
|
||||
for _, k := range m {
|
||||
r = append(r, k)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
type Set[T comparable] struct {
|
||||
items map[T]struct{}
|
||||
}
|
||||
|
|
@ -25,7 +39,7 @@ func (self *Set[T]) AddItems(val ...T) {
|
|||
}
|
||||
|
||||
func (self *Set[T]) String() string {
|
||||
return fmt.Sprintf("%#v", maps.Keys(self.items))
|
||||
return fmt.Sprintf("%#v", Keys(self.items))
|
||||
}
|
||||
|
||||
func (self *Set[T]) Remove(val T) {
|
||||
|
|
@ -60,7 +74,7 @@ func (self *Set[T]) Iterable() map[T]struct{} {
|
|||
}
|
||||
|
||||
func (self *Set[T]) AsSlice() []T {
|
||||
return maps.Keys(self.items)
|
||||
return Keys(self.items)
|
||||
}
|
||||
|
||||
func (self *Set[T]) Intersect(other *Set[T]) (ans *Set[T]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue