Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parallel-letter-frequency: false positive on 'wait for goroutines' #74

Open
bitfield opened this issue Dec 30, 2018 · 0 comments
Open

Comments

@bitfield
Copy link
Contributor

bitfield commented Dec 30, 2018

Solution 7ae34b6188784d06a7fd50faa6872bba is fine:

func ConcurrentFrequency(strings []string) FreqMap {
	results := make(chan FreqMap)
	m := FreqMap{}
	for _, currentString := range strings {
		go func(text string) {
			results <- Frequency(text)
		}(currentString)
	}
	for range strings {
		for k, v := range <-results {
			m[k] += v
		}
	}
	return m
}

but Exalysis thinks it's waiting for the goroutines to be done [most definitely my fault]:

Here is one thought for further improvement:
- It looks like you wait until all results have been received from the goroutines before starting to merge them. In fact, you can (and should) start processing as soon as you receive the first result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant