func lineCount(s string) int {
count := 0
for _, c := range s {
if c == '\n' {
count++
}
}
return count
}
func lineCount(s string) int {
count := 0
for _, c := range s {
if c == '\n' {
count++
}
}
return count
}
func newLine(r rune, c chan<- struct{}, wg sync.WaitGroup) {
if r == '\n' {
c <- struct{}
}
wc.Done()
}
func sumLines(c <-chan struct{}, result chan<- int) {
count := 0
for _ := range c {
count++
}
result <- count
}
func lineCount(s string) int {
c := make(chan struct{})
var wg sync.WaitGroup
for _, r := range s {
wg.Add(1)
go newLine(r, c, wg)
}
result := make(chan int)
go sumLines(c, result)
wg.Wait()
close(c)
return <-result
}
func newLine(r rune, c chan<- struct{}, wg sync.WaitGroup) {
if r == '\n' {
c <- struct{}
}
wc.Done()
}
func sumLines(c <-chan struct{}, result chan<- int) {
count := 0
for _ := range c {
count++
}
result <- count
}
func lineCount(s string) int {
c := make(chan struct{})
var wg sync.WaitGroup
for _, r := range s {
wg.Add(1)
go newLine(r, c, wg)
}
result := make(chan int)
go sumLines(c, result)
wg.Wait()
close(c)
return <-result
}
func newLine(s string, c chan<- int, wg sync.WaitGroup) {
count := 0
for _, r := range s {
if r == '\n' {
count++
}
}
c <- count
wc.Done()
}
func sumLines(c <-chan int, result chan<- int) {
count := 0
for miniCount := range c {
count += miniCount
}
result <- count
}
func lineCount(s string) int {
c := make(chan int)
var wg sync.WaitGroup
for i := 0; i < len(s)/MAGIC_NUMBER; i++ {
wg.Add(1)
go newLine(s[i*MAGIC_NUMBER : (i+1)*MAGIC_NUMBER], c, wg)
}
result := make(chan int)
go sumLines(c, result)
wg.Wait()
close(c)
return <-result
}
func newLine(s string, c chan<- int, wg sync.WaitGroup) {
count := 0
for _, r := range s {
if r == '\n' {
count++
}
}
c <- count
wc.Done()
}
func sumLines(c <-chan int, result chan<- int) {
count := 0
for miniCount := range c {
count += miniCount
}
result <- count
}
func lineCount(s string) int {
c := make(chan int)
var wg sync.WaitGroup
for i := 0; i < len(s)/MAGIC_NUMBER; i++ {
wg.Add(1)
go newLine(s[i*MAGIC_NUMBER : (i+1)*MAGIC_NUMBER], c, wg)
}
result := make(chan int)
go sumLines(c, result)
wg.Wait()
close(c)
return <-result
}