-
Notifications
You must be signed in to change notification settings - Fork 0
/
id.go
55 lines (44 loc) · 873 Bytes
/
id.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package lr0
import (
"fmt"
)
func dumpSymbol(s Symbol) string {
if n := s.Name(); n != "" {
return n
}
return fmt.Sprintf("#%v", s.Id())
}
func dumpId(id Id, r SymbolRegistry) string {
if s := r.SymbolName(id); s != "" {
return s
}
return fmt.Sprintf("#%v", id)
}
type readonlyIdSet interface {
Count() int
Has(id Id) bool
//IsEmpty() bool
//ForEach(fn func(Id))
}
type idSet map[Id]struct{}
func newIdSet(id ...Id) idSet {
return make(idSet).Add(id...)
}
func (s idSet) Add(id ...Id) idSet {
for _, v := range id {
s[v] = struct{}{}
}
return s
}
func (s idSet) Remove(id Id) { delete(s, id) }
func (s idSet) Count() int { return len(s) }
//func (s idSet) IsEmpty() bool { return len(s) == 0 }
//func (s idSet) ForEach(fn func(Id)) {
// for id := range s {
// fn(id)
// }
//}
func (s idSet) Has(id Id) bool {
_, ok := s[id]
return ok
}