mirror of
https://github.com/knight0zh/aoi.git
synced 2026-05-23 03:17:29 +08:00
优化
This commit is contained in:
24
aoi.go
24
aoi.go
@@ -1,12 +1,28 @@
|
||||
package aoi
|
||||
|
||||
import "sync"
|
||||
|
||||
type AOI interface {
|
||||
Add(entity *Entity) // 添加实体
|
||||
Delete(entity *Entity) // 移除实体
|
||||
Search(entity *Entity) (result []*Entity) // 范围查询
|
||||
Add(x, y float64, name string) // 添加实体
|
||||
Delete(x, y float64, name string) // 移除实体
|
||||
Search(x, y float64) (result []string) // 范围查询
|
||||
}
|
||||
|
||||
type Entity struct {
|
||||
X, Y float64
|
||||
Name string
|
||||
Key string
|
||||
}
|
||||
|
||||
var (
|
||||
resultPool sync.Pool
|
||||
entityPool sync.Pool
|
||||
)
|
||||
|
||||
func init() {
|
||||
resultPool.New = func() interface{} {
|
||||
return make([]string, 0, 500)
|
||||
}
|
||||
entityPool.New = func() interface{} {
|
||||
return &Entity{}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user