File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,27 @@ type IDGenerator struct {
4242 used map [string ]bool
4343}
4444
45+ // ensureInit initializes the internal map if not already.
46+ func (g * IDGenerator ) ensureInit () {
47+ if g .used == nil {
48+ g .used = make (map [string ]bool )
49+ }
50+ }
51+
4552// Generate an ID
4653func (g * IDGenerator ) Generate (value []byte , _ ast.NodeKind ) []byte {
54+ g .ensureInit ()
4755 return []byte (slug .Generate (string (value )))
4856}
4957
5058// Put an ID to the list of already used IDs
5159func (g * IDGenerator ) Put (value []byte ) {
60+ g .ensureInit ()
5261 g .used [util .BytesToReadOnlyString (value )] = true
5362}
63+
64+ // Has checks if the given ID is already used.
65+ func (g * IDGenerator ) Has (value []byte ) bool {
66+ (g * IDGenerator )
67+ return g .used [util .BytesToReadOnlyString (value )]
68+ }
You can’t perform that action at this time.
0 commit comments