/
entityid_set.go
37 lines (31 loc) · 782 Bytes
/
entityid_set.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
34
35
36
37
package common
// EntityIDSet is the data structure for a set of entity IDs
type EntityIDSet map[EntityID]struct{}
// Add adds an entity ID to EntityIDSet
func (es EntityIDSet) Add(id EntityID) {
es[id] = struct{}{}
}
// Del removes an entity ID from EntityIDSet
func (es EntityIDSet) Del(id EntityID) {
delete(es, id)
}
// Contains checks if entity ID is in EntityIDSet
func (es EntityIDSet) Contains(id EntityID) bool {
_, ok := es[id]
return ok
}
// ToList convert EntityIDSet to a slice of entity IDs
func (es EntityIDSet) ToList() []EntityID {
list := make([]EntityID, 0, len(es))
for eid := range es {
list = append(list, eid)
}
return list
}
func (es EntityIDSet) ForEach(cb func(eid EntityID) bool) {
for eid := range es {
if !cb(eid) {
break
}
}
}