github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/inspector/validation/utils.go (about) 1 package validation 2 3 // duplicateStrTracker is a map of strings to the number of times they have been tracked. 4 // It is a non-concurrent map, so it should only be used in a single goroutine. 5 // It is used to track duplicate strings. 6 type duplicateStrTracker map[string]int 7 8 // track stores the string and returns the number of times it has been tracked and whether it is a duplicate. 9 // If the string has not been tracked before, it is stored with a count of 1. 10 // If the string has been tracked before, the count is incremented. 11 // Args: 12 // 13 // s: the string to track 14 // 15 // Returns: 16 // The number of times this string has been tracked, e.g., 1 if it is the first time, 2 if it is the second time, etc. 17 func (d duplicateStrTracker) track(s string) int { 18 if _, ok := d[s]; !ok { 19 d[s] = 0 20 } 21 d[s]++ 22 23 return d[s] 24 }