From 183ee01b7a86e95917163e48094d00b957be23cc Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Tue, 25 Apr 2023 10:15:02 +0800 Subject: [PATCH] fix: return domain type --- base/bmap/any.go | 16 ++++++-------- base/bmap/comparable.go | 20 ++++++------------ base/bslice/any.go | 16 +++++++------- base/bslice/calculable.go | 44 +++++++-------------------------------- base/bslice/comparable.go | 16 +++++++------- base/bslice/ordered.go | 36 +++++++------------------------- 6 files changed, 43 insertions(+), 105 deletions(-) diff --git a/base/bmap/any.go b/base/bmap/any.go index dd101c0..352cfdd 100644 --- a/base/bmap/any.go +++ b/base/bmap/any.go @@ -11,11 +11,11 @@ import ( // ===================================================================================================================== // unsafe -func NewUnsafeAnyBMap[K comparable, V any]() AnyBMap[K, V] { +func NewUnsafeAnyBMap[K comparable, V any]() *UnsafeAnyBMap[K, V] { return &UnsafeAnyBMap[K, V]{mp: map[K]V{}} } -func NewUnsafeAnyBMapByMap[K comparable, V any](mp map[K]V) AnyBMap[K, V] { +func NewUnsafeAnyBMapByMap[K comparable, V any](mp map[K]V) *UnsafeAnyBMap[K, V] { if mp == nil { return NewUnsafeAnyBMap[K, V]() } @@ -190,19 +190,15 @@ func (x *UnsafeAnyBMap[K, V]) Replace(k K, ov, nv V) bool { // ===================================================================================================================== // safe -func NewSafeAnyBMap[K comparable, V any]() AnyBMap[K, V] { - return &SafeAnyBMap[K, V]{mp: &UnsafeAnyBMap[K, V]{ - mp: map[K]V{}, - }} +func NewSafeAnyBMap[K comparable, V any]() *SafeAnyBMap[K, V] { + return &SafeAnyBMap[K, V]{mp: NewUnsafeAnyBMap[K,V]()} } -func NewSafeAnyBMapByMap[K comparable, V any](mp map[K]V) AnyBMap[K, V] { +func NewSafeAnyBMapByMap[K comparable, V any](mp map[K]V) *SafeAnyBMap[K, V] { if mp == nil { return NewSafeAnyBMap[K, V]() } - return &SafeAnyBMap[K, V]{mp: &UnsafeAnyBMap[K, V]{ - mp: mp, - }} + return &SafeAnyBMap[K, V]{mp: NewUnsafeAnyBMapByMap[K,V](mp)} } type SafeAnyBMap[K comparable, V any] struct { diff --git a/base/bmap/comparable.go b/base/bmap/comparable.go index 1ea0a52..63c1a30 100644 --- a/base/bmap/comparable.go +++ b/base/bmap/comparable.go @@ -3,7 +3,7 @@ package bmap // ===================================================================================================================== // unsafe -func NewUnsafeComparableBMap[K comparable, V comparable]() ComparableBMap[K, V] { +func NewUnsafeComparableBMap[K comparable, V comparable]() *UnsafeComparableBMap[K, V] { return &UnsafeComparableBMap[K, V]{ UnsafeAnyBMap: &UnsafeAnyBMap[K, V]{ mp: make(map[K]V), @@ -11,7 +11,7 @@ func NewUnsafeComparableBMap[K comparable, V comparable]() ComparableBMap[K, V] } } -func NewUnsafeComparableBMapByMap[K comparable, V comparable](mp map[K]V) ComparableBMap[K, V] { +func NewUnsafeComparableBMapByMap[K comparable, V comparable](mp map[K]V) *UnsafeComparableBMap[K, V] { return &UnsafeComparableBMap[K, V]{ UnsafeAnyBMap: &UnsafeAnyBMap[K, V]{ mp: mp, @@ -34,23 +34,15 @@ func (x *UnsafeComparableBMap[K, V]) EqualByBMap(m AnyBMap[K, V]) bool { // ===================================================================================================================== // safe -func NewSafeComparableBMap[K comparable, V comparable]() ComparableBMap[K, V] { +func NewSafeComparableBMap[K comparable, V comparable]() *SafeComparableBMap[K, V] { return &SafeComparableBMap[K, V]{ - SafeAnyBMap: &SafeAnyBMap[K, V]{ - mp: &UnsafeAnyBMap[K, V]{ - mp: map[K]V{}, - }, - }, + SafeAnyBMap: NewSafeAnyBMap[K,V](), } } -func NewSafeComparableBMapByMap[K comparable, V comparable](mp map[K]V) ComparableBMap[K, V] { +func NewSafeComparableBMapByMap[K comparable, V comparable](mp map[K]V) *SafeComparableBMap[K, V] { return &SafeComparableBMap[K, V]{ - SafeAnyBMap: &SafeAnyBMap[K, V]{ - mp: &UnsafeAnyBMap[K, V]{ - mp: mp, - }, - }, + SafeAnyBMap: NewSafeAnyBMapByMap[K,V](mp), } } diff --git a/base/bslice/any.go b/base/bslice/any.go index 0b1730d..8883f6d 100644 --- a/base/bslice/any.go +++ b/base/bslice/any.go @@ -12,13 +12,13 @@ import ( // ===================================================================================================================== // unsafe -func NewUnsafeAnyBSlice[E any]() AnyBSlice[E] { +func NewUnsafeAnyBSlice[E any]() *UnsafeAnyBSlice[E] { return &UnsafeAnyBSlice[E]{ e: []E{}, } } -func NewUnsafeAnyBSliceBySlice[E any](s []E) AnyBSlice[E] { +func NewUnsafeAnyBSliceBySlice[E any](s []E) *UnsafeAnyBSlice[E] { return &UnsafeAnyBSlice[E]{ e: s, } @@ -430,17 +430,15 @@ func (x *UnsafeAnyBSlice[E]) SetByRangeE(index int, es []E) error { // ===================================================================================================================== // safe -func NewSafeAnyBSlice[E any]() AnyBSlice[E] { - return &UnsafeAnyBSlice[E]{ - e: []E{}, +func NewSafeAnyBSlice[E any]() *SafeAnyBSlice[E] { + return &SafeAnyBSlice[E]{ + es: NewUnsafeAnyBSlice[E](), } } -func NewSafeAnyBSliceBySlice[E any](e []E) AnyBSlice[E] { +func NewSafeAnyBSliceBySlice[E any](e []E) *SafeAnyBSlice[E] { return &SafeAnyBSlice[E]{ - es: &UnsafeAnyBSlice[E]{ - e: e, - }, + es: NewUnsafeAnyBSliceBySlice(e), } } diff --git a/base/bslice/calculable.go b/base/bslice/calculable.go index 60544eb..6bfb30a 100644 --- a/base/bslice/calculable.go +++ b/base/bslice/calculable.go @@ -9,27 +9,15 @@ import ( // ===================================================================================================================== // unsafe -func NewUnsafeCalculableBSlice[E btype.Integer | btype.Float]() CalculableBSlice[E] { +func NewUnsafeCalculableBSlice[E btype.Integer | btype.Float]() *UnsafeCalculableBSlice[E] { return &UnsafeCalculableBSlice[E]{ - UnsafeOrderedBSlice: &UnsafeOrderedBSlice[E]{ - UnsafeComparableBSlice: &UnsafeComparableBSlice[E]{ - UnsafeAnyBSlice: &UnsafeAnyBSlice[E]{ - e: nil, - }, - }, - }, + UnsafeOrderedBSlice: NewUnsafeOrderedBSlice[E](), } } -func NewUnsafeCalculableBSliceBySlice[E btype.Integer | btype.Float](s []E) CalculableBSlice[E] { +func NewUnsafeCalculableBSliceBySlice[E btype.Integer | btype.Float](s []E) *UnsafeCalculableBSlice[E] { return &UnsafeCalculableBSlice[E]{ - UnsafeOrderedBSlice: &UnsafeOrderedBSlice[E]{ - UnsafeComparableBSlice: &UnsafeComparableBSlice[E]{ - UnsafeAnyBSlice: &UnsafeAnyBSlice[E]{ - e: s, - }, - }, - }, + UnsafeOrderedBSlice: NewUnsafeOrderedBSliceBySlice[E](s), } } @@ -84,31 +72,15 @@ func (x *UnsafeCalculableBSlice[E]) Min() E { // ===================================================================================================================== // safe -func NewSafeCalculableBSlice[E btype.Integer | btype.Float]() CalculableBSlice[E] { +func NewSafeCalculableBSlice[E btype.Integer | btype.Float]() *SafeCalculableBSlice[E] { return &SafeCalculableBSlice[E]{ - SafeOrderedBSlice: &SafeOrderedBSlice[E]{ - SafeComparableBSlice: &SafeComparableBSlice[E]{ - SafeAnyBSlice: &SafeAnyBSlice[E]{ - es: &UnsafeAnyBSlice[E]{ - e: []E{}, - }, - }, - }, - }, + SafeOrderedBSlice: NewSafeOrderedBSlice[E](), } } -func NewSafeCalculableBSliceBySlice[E btype.Integer | btype.Float](s []E) CalculableBSlice[E] { +func NewSafeCalculableBSliceBySlice[E btype.Integer | btype.Float](s []E) *SafeCalculableBSlice[E] { return &SafeCalculableBSlice[E]{ - SafeOrderedBSlice: &SafeOrderedBSlice[E]{ - SafeComparableBSlice: &SafeComparableBSlice[E]{ - SafeAnyBSlice: &SafeAnyBSlice[E]{ - es: &UnsafeAnyBSlice[E]{ - e: s, - }, - }, - }, - }, + SafeOrderedBSlice: NewSafeOrderedBSliceBySlice[E](s), } } diff --git a/base/bslice/comparable.go b/base/bslice/comparable.go index 8db548b..5246450 100644 --- a/base/bslice/comparable.go +++ b/base/bslice/comparable.go @@ -3,15 +3,15 @@ package bslice // ===================================================================================================================== // unsafe -func NewUnsafeComparableBSlice[E comparable]() ComparableBSlice[E] { +func NewUnsafeComparableBSlice[E comparable]() *UnsafeComparableBSlice[E] { return &UnsafeComparableBSlice[E]{ - UnsafeAnyBSlice: &UnsafeAnyBSlice[E]{}, + UnsafeAnyBSlice: NewUnsafeAnyBSlice[E](), } } -func NewUnsafeComparableBSliceBySlice[E comparable](s []E) ComparableBSlice[E] { +func NewUnsafeComparableBSliceBySlice[E comparable](s []E) *UnsafeComparableBSlice[E] { return &UnsafeComparableBSlice[E]{ - UnsafeAnyBSlice: &UnsafeAnyBSlice[E]{e: s}, + UnsafeAnyBSlice: NewUnsafeAnyBSliceBySlice[E](s), } } @@ -34,15 +34,15 @@ func (x *UnsafeComparableBSlice[E]) Compact() { // ===================================================================================================================== // safe -func NewSafeComparableBSlice[E comparable]() ComparableBSlice[E] { +func NewSafeComparableBSlice[E comparable]() *SafeComparableBSlice[E] { return &SafeComparableBSlice[E]{ - SafeAnyBSlice: &SafeAnyBSlice[E]{}, + SafeAnyBSlice: NewSafeAnyBSlice[E](), } } -func NewSafeComparableBSliceBySlice[E comparable](s []E) ComparableBSlice[E] { +func NewSafeComparableBSliceBySlice[E comparable](s []E) *SafeComparableBSlice[E] { return &SafeComparableBSlice[E]{ - SafeAnyBSlice: &SafeAnyBSlice[E]{es: &UnsafeAnyBSlice[E]{e: s}}, + SafeAnyBSlice: NewSafeAnyBSliceBySlice[E](s), } } diff --git a/base/bslice/ordered.go b/base/bslice/ordered.go index cbbd8e5..021fdc2 100644 --- a/base/bslice/ordered.go +++ b/base/bslice/ordered.go @@ -7,23 +7,15 @@ import ( // ===================================================================================================================== // unsafe -func NewUnsafeOrderedBSlice[E btype.Ordered]() OrderedBSlice[E] { +func NewUnsafeOrderedBSlice[E btype.Ordered]() *UnsafeOrderedBSlice[E] { return &UnsafeOrderedBSlice[E]{ - UnsafeComparableBSlice: &UnsafeComparableBSlice[E]{ - UnsafeAnyBSlice: &UnsafeAnyBSlice[E]{ - e: nil, - }, - }, + UnsafeComparableBSlice: NewUnsafeComparableBSlice[E](), } } -func NewUnsafeOrderedBSliceBySlice[E btype.Ordered](s []E) OrderedBSlice[E] { +func NewUnsafeOrderedBSliceBySlice[E btype.Ordered](s []E) *UnsafeOrderedBSlice[E] { return &UnsafeOrderedBSlice[E]{ - UnsafeComparableBSlice: &UnsafeComparableBSlice[E]{ - UnsafeAnyBSlice: &UnsafeAnyBSlice[E]{ - e: s, - }, - }, + UnsafeComparableBSlice: NewUnsafeComparableBSliceBySlice[E](s), } } @@ -50,27 +42,15 @@ func (x *UnsafeOrderedBSlice[E]) BinarySearch(target E) (int, bool) { // ===================================================================================================================== // safe -func NewSafeOrderedBSlice[E btype.Integer | btype.Float]() OrderedBSlice[E] { +func NewSafeOrderedBSlice[E btype.Integer | btype.Float]() *SafeOrderedBSlice[E] { return &SafeOrderedBSlice[E]{ - SafeComparableBSlice: &SafeComparableBSlice[E]{ - SafeAnyBSlice: &SafeAnyBSlice[E]{ - es: &UnsafeAnyBSlice[E]{ - e: nil, - }, - }, - }, + SafeComparableBSlice: NewSafeComparableBSlice[E](), } } -func NewSafeOrderedBSliceBySlice[E btype.Integer | btype.Float](s []E) OrderedBSlice[E] { +func NewSafeOrderedBSliceBySlice[E btype.Integer | btype.Float](s []E) *SafeOrderedBSlice[E] { return &SafeOrderedBSlice[E]{ - SafeComparableBSlice: &SafeComparableBSlice[E]{ - SafeAnyBSlice: &SafeAnyBSlice[E]{ - es: &UnsafeAnyBSlice[E]{ - e: s, - }, - }, - }, + SafeComparableBSlice: NewSafeComparableBSliceBySlice[E](s), } }