package letter

import (
	"sync"
	"time"
)

// MyConcurrentFrequency ...
func MyConcurrentFrequency(input []string) FreqMap {
	var ProcMap = struct {
		sync.RWMutex
		m map[rune]int
	}{m: make(map[rune]int)}

	var procCnt = len(input)
	for _, chunk := range input {
		go func(chunk string) {
			for _, rn := range chunk {
				ProcMap.Lock()
				ProcMap.m[rn]++
				ProcMap.Unlock()
			}
			procCnt--
		}(chunk)
	}
	for procCnt > 0 {
		time.Sleep(time.Millisecond)
	}
	return ProcMap.m
}
