You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
335 B
20 lines
335 B
package wc
|
|
|
|
func GetLineCount(chunk []byte) int64 {
|
|
var count int64
|
|
for _, b := range chunk {
|
|
if b == '\n' {
|
|
count++
|
|
}
|
|
}
|
|
return count
|
|
}
|
|
|
|
func ConcurrentChunkCounter(chunks <-chan []byte, counts chan<- int64) {
|
|
var totalCount int64
|
|
for chunk := range chunks {
|
|
totalCount += GetLineCount(chunk)
|
|
}
|
|
counts <- totalCount
|
|
}
|