-
Notifications
You must be signed in to change notification settings - Fork 5
/
aoi.go
33 lines (27 loc) · 876 Bytes
/
aoi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package aoi
import "sync"
// AOI (Area of Interest) represents an interface for managing entities within a specific area.
type AOI interface {
Add(x, y float64, name string) // Add an entity to the AOI
Delete(x, y float64, name string) // Delete an entity from the AOI
Search(x, y float64) (result []string) // Search for entities within a specified range
}
// Entity represents an object with coordinates and a key.
type Entity struct {
X, Y float64
Key string
}
var (
resultPool sync.Pool // Pool for recycling result slices
entityPool sync.Pool // Pool for recycling Entity objects
)
func init() {
// Initialize the resultPool to recycle result slices
resultPool.New = func() interface{} {
return make([]string, 0, 500)
}
// Initialize the entityPool to recycle Entity objects
entityPool.New = func() interface{} {
return &Entity{}
}
}