mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-08-16 10:00:24 +03:00
Use stdlib maps/slices
This commit is contained in:
parent
e7ed5716a9
commit
405f5ce148
@ -10,6 +10,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -17,9 +18,6 @@ import (
|
|||||||
"kitty/tools/tui/loop"
|
"kitty/tools/tui/loop"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/images"
|
"kitty/tools/utils/images"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@ -365,7 +363,7 @@ func run_get_loop(opts *Options, args []string) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(requested_mimes) > 0 {
|
if len(requested_mimes) > 0 {
|
||||||
lp.QueueWriteString(encode(basic_metadata, strings.Join(maps.Keys(requested_mimes), " ")))
|
lp.QueueWriteString(encode(basic_metadata, strings.Join(utils.Keys(requested_mimes), " ")))
|
||||||
} else {
|
} else {
|
||||||
lp.Quit(0)
|
lp.Quit(0)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ package diff
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -12,8 +13,6 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/images"
|
"kitty/tools/utils/images"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -18,7 +19,6 @@ import (
|
|||||||
|
|
||||||
"github.com/dlclark/regexp2"
|
"github.com/dlclark/regexp2"
|
||||||
"github.com/seancfoley/ipaddress-go/ipaddr"
|
"github.com/seancfoley/ipaddress-go/ipaddr"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
"kitty"
|
"kitty"
|
||||||
"kitty/tools/config"
|
"kitty/tools/config"
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"kitty"
|
"kitty"
|
||||||
|
"maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -21,6 +22,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -36,8 +38,6 @@ import (
|
|||||||
"kitty/tools/utils/shlex"
|
"kitty/tools/utils/shlex"
|
||||||
"kitty/tools/utils/shm"
|
"kitty/tools/utils/shm"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ func prepare_script(script string, replacements map[string]string) string {
|
|||||||
if _, found := replacements["EXPORT_HOME_CMD"]; !found {
|
if _, found := replacements["EXPORT_HOME_CMD"]; !found {
|
||||||
replacements["EXPORT_HOME_CMD"] = ""
|
replacements["EXPORT_HOME_CMD"] = ""
|
||||||
}
|
}
|
||||||
keys := maps.Keys(replacements)
|
keys := utils.Keys(replacements)
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
keys[i] = "\\b" + key + "\\b"
|
keys[i] = "\\b" + key + "\\b"
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ package themes
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -16,9 +18,6 @@ import (
|
|||||||
"kitty/tools/tui/readline"
|
"kitty/tools/tui/readline"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -25,7 +26,6 @@ import (
|
|||||||
"kitty/tools/utils/humanize"
|
"kitty/tools/utils/humanize"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -18,7 +19,6 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
"kitty"
|
"kitty"
|
||||||
"kitty/tools/cli/markup"
|
"kitty/tools/cli/markup"
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
@ -21,8 +22,6 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/style"
|
"kitty/tools/utils/style"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -4,6 +4,7 @@ package unicode_input
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -11,8 +12,6 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/style"
|
"kitty/tools/utils/style"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -8,8 +8,6 @@ import (
|
|||||||
|
|
||||||
"kitty/tools/cli/markup"
|
"kitty/tools/cli/markup"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@ -23,7 +21,7 @@ func fish_completion_script(commands []string) (string, error) {
|
|||||||
"kitten": true,
|
"kitten": true,
|
||||||
}
|
}
|
||||||
if len(commands) == 0 {
|
if len(commands) == 0 {
|
||||||
commands = append(commands, maps.Keys(all_commands)...)
|
commands = append(commands, utils.Keys(all_commands)...)
|
||||||
}
|
}
|
||||||
script := strings.Builder{}
|
script := strings.Builder{}
|
||||||
script.WriteString(`function __ksi_completions
|
script.WriteString(`function __ksi_completions
|
||||||
|
@ -7,10 +7,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"kitty"
|
"kitty"
|
||||||
|
@ -4,10 +4,9 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -16,7 +17,6 @@ import (
|
|||||||
"kitty/tools/tui/loop"
|
"kitty/tools/tui/loop"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/style"
|
"kitty/tools/utils/style"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@ -277,7 +275,7 @@ func (h *handler) on_wakeup() (err error) {
|
|||||||
switch h.state {
|
switch h.state {
|
||||||
case SCANNING_FAMILIES:
|
case SCANNING_FAMILIES:
|
||||||
h.state = LISTING_FAMILIES
|
h.state = LISTING_FAMILIES
|
||||||
h.family_list.UpdateFamilies(utils.StableSortWithKey(maps.Keys(h.fonts), strings.ToLower))
|
h.family_list.UpdateFamilies(utils.StableSortWithKey(utils.Keys(h.fonts), strings.ToLower))
|
||||||
case LISTING_FAMILIES:
|
case LISTING_FAMILIES:
|
||||||
}
|
}
|
||||||
return h.draw_screen()
|
return h.draw_screen()
|
||||||
|
@ -7,12 +7,10 @@ import (
|
|||||||
"kitty/tools/tui/loop"
|
"kitty/tools/tui/loop"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@ -309,5 +307,5 @@ func ResolveShortcuts(actions []*KeyAction) []*KeyAction {
|
|||||||
action_map[key] = ac
|
action_map[key] = ac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return maps.Values(action_map)
|
return utils.Values(action_map)
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/zeebo/xxh3"
|
"github.com/zeebo/xxh3"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// If no BlockSize is specified in the rsync instance, this value is used.
|
// If no BlockSize is specified in the rsync instance, this value is used.
|
||||||
|
@ -7,12 +7,12 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
)
|
)
|
||||||
|
@ -10,11 +10,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -28,8 +30,6 @@ import (
|
|||||||
"kitty/tools/utils/style"
|
"kitty/tools/utils/style"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/process"
|
"github.com/shirou/gopsutil/v3/process"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -594,7 +594,7 @@ func patch_conf(text, theme_name string) string {
|
|||||||
}
|
}
|
||||||
ntext = text + addition
|
ntext = text + addition
|
||||||
}
|
}
|
||||||
pat = utils.MustCompile(fmt.Sprintf(`(?m)^\s*(%s)\b`, strings.Join(maps.Keys(AllColorSettingNames), "|")))
|
pat = utils.MustCompile(fmt.Sprintf(`(?m)^\s*(%s)\b`, strings.Join(utils.Keys(AllColorSettingNames), "|")))
|
||||||
return pat.ReplaceAllString(ntext, `# $1`)
|
return pat.ReplaceAllString(ntext, `# $1`)
|
||||||
}
|
}
|
||||||
func is_kitty_gui_cmdline(cmd ...string) bool {
|
func is_kitty_gui_cmdline(cmd ...string) bool {
|
||||||
@ -809,12 +809,12 @@ func (self *Themes) At(x int) *Theme {
|
|||||||
func (self *Themes) Names() []string { return self.index_map }
|
func (self *Themes) Names() []string { return self.index_map }
|
||||||
|
|
||||||
func (self *Themes) create_index_map() {
|
func (self *Themes) create_index_map() {
|
||||||
self.index_map = maps.Keys(self.name_map)
|
self.index_map = utils.Keys(self.name_map)
|
||||||
self.index_map = utils.StableSortWithKey(self.index_map, strings.ToLower)
|
self.index_map = utils.StableSortWithKey(self.index_map, strings.ToLower)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Themes) Filtered(is_ok func(*Theme) bool) *Themes {
|
func (self *Themes) Filtered(is_ok func(*Theme) bool) *Themes {
|
||||||
themes := utils.Filter(maps.Values(self.name_map), is_ok)
|
themes := utils.Filter(utils.Values(self.name_map), is_ok)
|
||||||
ans := Themes{name_map: make(map[string]*Theme, len(themes))}
|
ans := Themes{name_map: make(map[string]*Theme, len(themes))}
|
||||||
for _, theme := range themes {
|
for _, theme := range themes {
|
||||||
ans.name_map[theme.metadata.Name] = theme
|
ans.name_map[theme.metadata.Name] = theme
|
||||||
|
@ -15,8 +15,6 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/images"
|
"kitty/tools/utils/images"
|
||||||
"kitty/tools/utils/shm"
|
"kitty/tools/utils/shm"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@ -137,7 +135,7 @@ func (self *ImageCollection) ResizeForPageSize(width, height int) {
|
|||||||
defer self.mutex.Unlock()
|
defer self.mutex.Unlock()
|
||||||
|
|
||||||
ctx := images.Context{}
|
ctx := images.Context{}
|
||||||
keys := maps.Keys(self.images)
|
keys := utils.Keys(self.images)
|
||||||
ctx.Parallel(0, len(keys), func(nums <-chan int) {
|
ctx.Parallel(0, len(keys), func(nums <-chan int) {
|
||||||
for i := range nums {
|
for i := range nums {
|
||||||
img := self.images[keys[i]]
|
img := self.images[keys[i]]
|
||||||
@ -295,7 +293,7 @@ func (self *ImageCollection) LoadAll() {
|
|||||||
self.mutex.Lock()
|
self.mutex.Lock()
|
||||||
defer self.mutex.Unlock()
|
defer self.mutex.Unlock()
|
||||||
ctx := images.Context{}
|
ctx := images.Context{}
|
||||||
all := maps.Values(self.images)
|
all := utils.Values(self.images)
|
||||||
ctx.Parallel(0, len(self.images), func(nums <-chan int) {
|
ctx.Parallel(0, len(self.images), func(nums <-chan int) {
|
||||||
for i := range nums {
|
for i := range nums {
|
||||||
img := all[i]
|
img := all[i]
|
||||||
|
@ -4,10 +4,9 @@ package loop
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
"kitty/tools/tty"
|
"kitty/tools/tty"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,7 @@ package sgr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@ -11,8 +12,6 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/style"
|
"kitty/tools/utils/style"
|
||||||
"kitty/tools/wcswidth"
|
"kitty/tools/wcswidth"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -6,14 +6,13 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
"kitty"
|
"kitty"
|
||||||
"kitty/tools/tty"
|
"kitty/tools/tty"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
|
@ -4,12 +4,11 @@ package subseq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/images"
|
"kitty/tools/utils/images"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -5,10 +5,10 @@ package unicode_names
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -23,7 +24,6 @@ import (
|
|||||||
|
|
||||||
"github.com/edwvee/exiffix"
|
"github.com/edwvee/exiffix"
|
||||||
"github.com/kovidgoyal/imaging"
|
"github.com/kovidgoyal/imaging"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
@ -4,12 +4,26 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
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 {
|
type Set[T comparable] struct {
|
||||||
items map[T]struct{}
|
items map[T]struct{}
|
||||||
}
|
}
|
||||||
@ -25,7 +39,7 @@ func (self *Set[T]) AddItems(val ...T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Set[T]) String() string {
|
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) {
|
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 {
|
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]) {
|
func (self *Set[T]) Intersect(other *Set[T]) (ans *Set[T]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user