rename mapreduce to mr
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package mapreduce
|
package mr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -16,7 +16,7 @@ const (
|
|||||||
minWorkers = 1
|
minWorkers = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrCancelWithNil = errors.New("mapreduce cancelled with nil")
|
var ErrCancelWithNil = errors.New("mr cancelled with nil")
|
||||||
|
|
||||||
type (
|
type (
|
||||||
GenerateFunc func(source chan<- interface{})
|
GenerateFunc func(source chan<- interface{})
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package mapreduce
|
package mr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"zero/core/mapreduce"
|
"zero/core/mr"
|
||||||
|
|
||||||
"github.com/google/gops/agent"
|
"github.com/google/gops/agent"
|
||||||
)
|
)
|
||||||
@@ -52,7 +52,7 @@ func enumerateLines(filename string) chan string {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapper(filename interface{}, writer mapreduce.Writer, cancel func(error)) {
|
func mapper(filename interface{}, writer mr.Writer, cancel func(error)) {
|
||||||
if len(*stopOnFile) > 0 && path.Base(filename.(string)) == *stopOnFile {
|
if len(*stopOnFile) > 0 && path.Base(filename.(string)) == *stopOnFile {
|
||||||
fmt.Printf("Stop on file: %s\n", *stopOnFile)
|
fmt.Printf("Stop on file: %s\n", *stopOnFile)
|
||||||
cancel(errors.New("stop on file"))
|
cancel(errors.New("stop on file"))
|
||||||
@@ -80,7 +80,7 @@ func mapper(filename interface{}, writer mapreduce.Writer, cancel func(error)) {
|
|||||||
writer.Write(result)
|
writer.Write(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func reducer(input <-chan interface{}, writer mapreduce.Writer, cancel func(error)) {
|
func reducer(input <-chan interface{}, writer mr.Writer, cancel func(error)) {
|
||||||
var result int
|
var result int
|
||||||
|
|
||||||
for count := range input {
|
for count := range input {
|
||||||
@@ -110,7 +110,7 @@ func main() {
|
|||||||
fmt.Println("Processing, please wait...")
|
fmt.Println("Processing, please wait...")
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
result, err := mapreduce.MapReduce(func(source chan<- interface{}) {
|
result, err := mr.MapReduce(func(source chan<- interface{}) {
|
||||||
filepath.Walk(*dir, func(fpath string, f os.FileInfo, err error) error {
|
filepath.Walk(*dir, func(fpath string, f os.FileInfo, err error) error {
|
||||||
if !f.IsDir() && path.Ext(fpath) == ".go" {
|
if !f.IsDir() && path.Ext(fpath) == ".go" {
|
||||||
source <- fpath
|
source <- fpath
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"zero/core/mapreduce"
|
"zero/core/mr"
|
||||||
"zero/core/timex"
|
"zero/core/timex"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
start := timex.Now()
|
start := timex.Now()
|
||||||
|
|
||||||
mapreduce.FinishVoid(func() {
|
mr.FinishVoid(func() {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}, func() {
|
}, func() {
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
@@ -20,7 +20,7 @@ func main() {
|
|||||||
}, func() {
|
}, func() {
|
||||||
time.Sleep(time.Second * 6)
|
time.Sleep(time.Second * 6)
|
||||||
}, func() {
|
}, func() {
|
||||||
if err := mapreduce.Finish(func() error {
|
if err := mr.Finish(func() error {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
return nil
|
return nil
|
||||||
}, func() error {
|
}, func() error {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"zero/core/mapreduce"
|
"zero/core/mr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -18,13 +18,13 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var allFriends []string
|
var allFriends []string
|
||||||
for v := range mapreduce.Map(func(source chan<- interface{}) {
|
for v := range mr.Map(func(source chan<- interface{}) {
|
||||||
for _, each := range persons {
|
for _, each := range persons {
|
||||||
source <- each
|
source <- each
|
||||||
}
|
}
|
||||||
}, func(item interface{}, writer mapreduce.Writer) {
|
}, func(item interface{}, writer mr.Writer) {
|
||||||
writer.Write(friends[item.(string)])
|
writer.Write(friends[item.(string)])
|
||||||
}, mapreduce.WithWorkers(100)) {
|
}, mr.WithWorkers(100)) {
|
||||||
allFriends = append(allFriends, v.([]string)...)
|
allFriends = append(allFriends, v.([]string)...)
|
||||||
}
|
}
|
||||||
fmt.Println(allFriends)
|
fmt.Println(allFriends)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"zero/core/lang"
|
"zero/core/lang"
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/mapreduce"
|
"zero/core/mr"
|
||||||
"zero/core/proc"
|
"zero/core/proc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,17 +47,17 @@ func main() {
|
|||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
mapreduce.MapReduce(func(source chan<- interface{}) {
|
mr.MapReduce(func(source chan<- interface{}) {
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
source <- i
|
source <- i
|
||||||
}
|
}
|
||||||
}, func(item interface{}, writer mapreduce.Writer, cancel func(error)) {
|
}, func(item interface{}, writer mr.Writer, cancel func(error)) {
|
||||||
if item.(int) == 40 {
|
if item.(int) == 40 {
|
||||||
cancel(errors.New("any"))
|
cancel(errors.New("any"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writer.Write(item)
|
writer.Write(item)
|
||||||
}, func(pipe <-chan interface{}, writer mapreduce.Writer, cancel func(error)) {
|
}, func(pipe <-chan interface{}, writer mr.Writer, cancel func(error)) {
|
||||||
list := make([]int, 0)
|
list := make([]int, 0)
|
||||||
for p := range pipe {
|
for p := range pipe {
|
||||||
list = append(list, p.(int))
|
list = append(list, p.(int))
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"zero/core/mapreduce"
|
"zero/core/mr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
mapreduce.MapReduceVoid(func(source chan<- interface{}) {
|
mr.MapReduceVoid(func(source chan<- interface{}) {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
source <- i
|
source <- i
|
||||||
}
|
}
|
||||||
}, func(item interface{}, writer mapreduce.Writer, cancel func(error)) {
|
}, func(item interface{}, writer mr.Writer, cancel func(error)) {
|
||||||
i := item.(int)
|
i := item.(int)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
"zero/core/hash"
|
"zero/core/hash"
|
||||||
"zero/core/lang"
|
"zero/core/lang"
|
||||||
"zero/core/logx"
|
"zero/core/logx"
|
||||||
"zero/core/mapreduce"
|
"zero/core/mr"
|
||||||
"zero/core/stringx"
|
"zero/core/stringx"
|
||||||
"zero/tools/goctl/api/apigen"
|
"zero/tools/goctl/api/apigen"
|
||||||
"zero/tools/goctl/api/dartgen"
|
"zero/tools/goctl/api/dartgen"
|
||||||
@@ -345,7 +345,7 @@ func main() {
|
|||||||
logx.Disable()
|
logx.Disable()
|
||||||
|
|
||||||
done := make(chan lang.PlaceholderType)
|
done := make(chan lang.PlaceholderType)
|
||||||
mapreduce.FinishVoid(func() {
|
mr.FinishVoid(func() {
|
||||||
if os.Getenv(autoUpdate) != "off" && !stringx.Contains(os.Args, "-iu") {
|
if os.Getenv(autoUpdate) != "off" && !stringx.Contains(os.Args, "-iu") {
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user