优化代码

This commit is contained in:
刘祥超
2023-07-18 11:21:39 +08:00
parent 734cf81ff0
commit 5928875623

View File

@@ -13,8 +13,8 @@ type FixedSet struct {
maxSize int maxSize int
locker sync.RWMutex locker sync.RWMutex
m map[interface{}]zero.Zero m map[any]zero.Zero
keys []interface{} keys []any
} }
func NewFixedSet(maxSize int) *FixedSet { func NewFixedSet(maxSize int) *FixedSet {
@@ -23,11 +23,11 @@ func NewFixedSet(maxSize int) *FixedSet {
} }
return &FixedSet{ return &FixedSet{
maxSize: maxSize, maxSize: maxSize,
m: map[interface{}]zero.Zero{}, m: map[any]zero.Zero{},
} }
} }
func (this *FixedSet) Push(item interface{}) { func (this *FixedSet) Push(item any) {
this.locker.Lock() this.locker.Lock()
_, ok := this.m[item] _, ok := this.m[item]
if !ok { if !ok {
@@ -44,7 +44,7 @@ func (this *FixedSet) Push(item interface{}) {
this.locker.Unlock() this.locker.Unlock()
} }
func (this *FixedSet) Has(item interface{}) bool { func (this *FixedSet) Has(item any) bool {
this.locker.RLock() this.locker.RLock()
defer this.locker.RUnlock() defer this.locker.RUnlock()
@@ -60,7 +60,7 @@ func (this *FixedSet) Size() int {
func (this *FixedSet) Reset() { func (this *FixedSet) Reset() {
this.locker.Lock() this.locker.Lock()
this.m = map[interface{}]zero.Zero{} this.m = map[any]zero.Zero{}
this.keys = nil this.keys = nil
this.locker.Unlock() this.locker.Unlock()
} }