From c8d3b795c433a63c365257c87ab1902a6b8535f3 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sat, 10 May 2025 04:57:59 +0800 Subject: [PATCH] 1 (#52) --- map/map.go | 28 +++++++--------------------- reqf/cookie.go | 10 ++++++++++ sync/Map.go | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/map/map.go b/map/map.go index 5af80be..209e278 100644 --- a/map/map.go +++ b/map/map.go @@ -1,24 +1,10 @@ package part -import ( - "sync" -) - -type Map struct{ - m sync.Map - New func()interface{} -} - -func (t *Map) Get(key interface{})interface{}{ - if val,ok := t.m.Load(key);ok{return val} - return t.Set(key, t.New()) +func Contains[T comparable, S any](s map[T]S, keys ...T) (missKey []T) { + for _, tk := range keys { + if _, ok := s[tk]; !ok { + missKey = append(missKey, tk) + } + } + return } - -func (t *Map) Del(key interface{}){ - t.m.Delete(key) -} - -func (t *Map) Set(key interface{},val interface{})interface{}{ - t.m.Store(key, val) - return val -} \ No newline at end of file diff --git a/reqf/cookie.go b/reqf/cookie.go index 7e8cf1e..fb06cae 100644 --- a/reqf/cookie.go +++ b/reqf/cookie.go @@ -2,6 +2,7 @@ package part import ( "encoding/json" + "iter" "net" "net/http" "strings" @@ -91,6 +92,15 @@ func Cookies_String_2_Map(Cookies string) (o map[string]string) { return } +func Iter_2_Cookies_String(Cookies iter.Seq2[string, string]) (o string) { + for k, v := range Cookies { + o += k + `=` + v + `; ` + } + t := []rune(o) + o = string(t[:len(t)-2]) + return +} + func Map_2_Cookies_String(Cookies map[string]string) (o string) { if len(Cookies) == 0 { return "" diff --git a/sync/Map.go b/sync/Map.go index 10eb6d4..88fc369 100644 --- a/sync/Map.go +++ b/sync/Map.go @@ -122,3 +122,18 @@ func Copy[T comparable, S any](s map[T]S) map[T]S { } return t } + +func StoreAll[T comparable, S any, A, B any](d MapFunc[A, B], s map[T]S) { + for k, v := range s { + d.Store(any(k).(A), any(v).(B)) + } +} + +func Contains[A, B any](m MapFunc[A, B], keys ...A) (missKey []A) { + for _, tk := range keys { + if _, ok := m.Load(tk); !ok { + missKey = append(missKey, tk) + } + } + return +} -- 2.39.2