1
0
mirror of https://github.com/fumiama/dupimage.git synced 2026-06-27 07:30:28 +08:00

去重恢复单线程

This commit is contained in:
源文雨
2022-07-25 23:12:34 +08:00
parent 98697edfc8
commit 4fb796cea5

37
main.go
View File

@@ -106,7 +106,7 @@ func main() {
name: n, name: n,
dh: dh, dh: dh,
}) })
fmt.Print("scan: ", len(chklst), " / ", len(imgs), "\r") fmt.Print("read: ", len(chklst), " / ", len(imgs), "\r")
mu.Unlock() mu.Unlock()
_ = f.Close() _ = f.Close()
} }
@@ -118,9 +118,13 @@ func main() {
fmt.Println("read file success, comparing...") fmt.Println("read file success, comparing...")
duplis := make(map[string]uint, len(chklst)) duplis := make(map[string]uint, len(chklst))
sameset := make([][]uint, 0) sameset := make([][]uint, 0)
wg.Add(len(chklst))
for i := 0; i < len(chklst); i++ { for i := 0; i < len(chklst); i++ {
go func(i int) { fmt.Print("compare: ", i, " / ", len(chklst), "\r")
_, ok := duplis[chklst[i].name]
if ok {
continue
}
isfirst := true
for j := len(chklst) - 1; j > i; j-- { for j := len(chklst) - 1; j > i; j-- {
dis, err := chklst[i].dh.Distance(chklst[j].dh) dis, err := chklst[i].dh.Distance(chklst[j].dh)
if err != nil { if err != nil {
@@ -128,30 +132,41 @@ func main() {
continue continue
} }
if uint(dis) < throttle { if uint(dis) < throttle {
mu.Lock() x, ok := duplis[chklst[j].name]
if x, ok := duplis[chklst[j].name]; ok && x != uint(i) { if ok {
LOP: LOP:
for k, set := range sameset { for k, set := range sameset {
for _, item := range set { for _, item := range set {
if item == x { if x == item {
if isfirst {
sameset[k] = append(sameset[k], uint(i)) sameset[k] = append(sameset[k], uint(i))
duplis[chklst[i].name] = uint(i) duplis[chklst[i].name] = uint(i)
isfirst = false
} else {
INNERLOP:
for l, set := range sameset {
for _, item := range set {
if item == uint(i) {
sameset[k] = append(sameset[k], set...)
sameset = append(sameset[:l], sameset[l+1:]...)
break INNERLOP
}
}
}
}
break LOP break LOP
} }
} }
} }
} else if !ok { } else if isfirst {
sameset = append(sameset, []uint{uint(i)}) sameset = append(sameset, []uint{uint(i)})
duplis[chklst[i].name] = uint(i) duplis[chklst[i].name] = uint(i)
isfirst = false
} }
duplis[chklst[j].name] = uint(i) duplis[chklst[j].name] = uint(i)
mu.Unlock()
} }
} }
wg.Done()
}(i)
} }
wg.Wait()
fmt.Println("compare file success") fmt.Println("compare file success")
if len(sameset) > 0 { if len(sameset) > 0 {
dupset := make(map[uint][]string, len(sameset)) dupset := make(map[uint][]string, len(sameset))