Diff returns all new strings collected since the last time diff was called
()
| 136 | |
| 137 | // Diff returns all new strings collected since the last time diff was called |
| 138 | func (d *DistinctString) Diff() ([]string, error) { |
| 139 | // can check diffEnabled without lock because it is not modified after creation |
| 140 | if !d.diffEnabled { |
| 141 | return nil, errDiffNotEnabled |
| 142 | } |
| 143 | |
| 144 | d.mtx.Lock() |
| 145 | defer d.mtx.Unlock() |
| 146 | |
| 147 | ss := make([]string, 0, len(d.new)) |
| 148 | |
| 149 | for k := range d.new { |
| 150 | ss = append(ss, k) |
| 151 | } |
| 152 | |
| 153 | clear(d.new) |
| 154 | sort.Strings(ss) |
| 155 | return ss, nil |
| 156 | } |