fix: 优化 go1.21 以下项目的兼容性

This commit is contained in:
kercylan98 2023-08-22 14:06:20 +08:00
parent a1c15a2c26
commit ab90fa8928
3 changed files with 8 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package counter
import (
"fmt"
"github.com/kercylan98/minotaur/utils/generic"
"github.com/kercylan98/minotaur/utils/hash"
"sync"
"time"
)
@ -151,9 +152,9 @@ func (slf *Counter[K, V]) ResetExpiredMark(mark, key K) {
// ResetAll 重置所有计数
func (slf *Counter[K, V]) ResetAll() {
slf.lock.Lock()
clear(slf.c)
clear(slf.dr)
clear(slf.drm)
hash.Clear(slf.c)
hash.Clear(slf.dr)
hash.Clear(slf.drm)
slf.lock.Unlock()
}

View File

@ -36,7 +36,7 @@ func (slf *Priority[V]) Cap() int {
// Clear 清空切片
func (slf *Priority[V]) Clear() {
clear(slf.items)
slf.items = slf.items[:0]
}
// Append 添加元素

View File

@ -1,5 +1,7 @@
package sole
import "github.com/kercylan98/minotaur/utils/hash"
// NewOnce 创建一个用于数据取值去重的结构实例
func NewOnce[V any]() *Once[V] {
once := &Once[V]{
@ -31,5 +33,5 @@ func (slf *Once[V]) Reset(key ...any) {
}
return
}
clear(slf.r)
hash.Clear(slf.r)
}