Skip to content

Commit

Permalink
fix: return domain type
Browse files Browse the repository at this point in the history
  • Loading branch information
songzhibin97 committed Apr 25, 2023
1 parent a7b7c74 commit 183ee01
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 105 deletions.
16 changes: 6 additions & 10 deletions base/bmap/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
}
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 6 additions & 14 deletions base/bmap/comparable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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),
},
}
}

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,
Expand All @@ -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),
}
}

Expand Down
16 changes: 7 additions & 9 deletions base/bslice/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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),
}
}

Expand Down
44 changes: 8 additions & 36 deletions base/bslice/calculable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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),
}
}

Expand Down
16 changes: 8 additions & 8 deletions base/bslice/comparable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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),
}
}

Expand Down
36 changes: 8 additions & 28 deletions base/bslice/ordered.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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),
}
}

Expand Down

0 comments on commit 183ee01

Please sign in to comment.