sunty
2019-07-18 6a413e1d7d485f506e81c669bc692868c29cefb9
shardmap/shardmap.go
@@ -4,8 +4,8 @@
import (
   "sync"
    "encoding/json"
    "fmt"
    //"encoding/json"
    //"fmt"
)
var commonmux sync.Mutex
@@ -26,7 +26,7 @@
var Count = make(chan int)
type wfOp func(a, b string) float32
type wfOp func(a []byte, b string) float32
/**
* @param uint8, shardCnt must be pow of two
@@ -78,11 +78,9 @@
}
// modify by long.
func (s *ShardMap) Walk(wf wfOp, cfrom string) ([]byte){
func (s *ShardMap) Walk(wf wfOp, cfrom []byte) ( map[string]float32 ){
    var wg sync.WaitGroup
    var second float32 
    var buf []byte
    var err error
    ids := make(map[string]float32)
   for _, si := range s.shards {
@@ -92,7 +90,7 @@
        wg.Add(1)
        
      go func(st *shardItem, fw wfOp, cf string) {
      go func(st *shardItem, fw wfOp, cf []byte) {
            defer wg.Done()
            commonmux.Lock()
         for id, feature := range st.data {
@@ -110,13 +108,8 @@
    wg.Wait()
    buf, err = json.Marshal(ids)
    if err != nil {
        fmt.Println("compare json err")
            buf = nil
    }
    return buf
    return ids
}
// print all