zhangzengfei
2024-04-18 bdcc9624341ee34298be74a706b09f12f8306456
cache/shardmap/shardmap.go
@@ -29,7 +29,7 @@
var Count = make(chan int)
type wfOp func(a []byte, b string) float32
type wfOp func(a, b []float32) float32
/**
* @param uint8, shardCnt must be pow of two
@@ -90,7 +90,7 @@
   value interface{}
}
func (s *ShardMap) Walk(wf wfOp, sourceFea []byte, baseScore float32) (targets []*protomsg.SdkCompareEach) {
func (s *ShardMap) Walk(wf wfOp, sourceFea []float32, baseScore float32) (targets []*protomsg.SdkCompareEach) {
   var wg sync.WaitGroup
   var lock sync.Mutex
   for _, si := range s.shards {
@@ -102,18 +102,18 @@
      wg.Add(1)
      go func(st *shardItem, fw wfOp, sf []byte, baseSec float32) {
      go func(st *shardItem, fn wfOp, srcFeat []float32, baseSec float32) {
         defer wg.Done()
         for _, feature := range st.data {
            if eif, ok := feature.(*db.FeatureCacheBase); ok {
            if item, ok := feature.(*db.FeatureCacheBase); ok {
               score := float32(0)
               score = fw(sf, eif.FaceFeature)
               score = fn(srcFeat, item.FaceFeature)
               if score > 0 && score >= baseScore {
                  lock.Lock()
                  targets = append(targets, &protomsg.SdkCompareEach{
                     Id:           eif.Id,
                     Id:           item.Id,
                     CompareScore: score,
                     Tableid:      eif.TableId,
                     Tableid:      item.TableId,
                  })
                  lock.Unlock()
               }