Remove handled images from slice

This commit is contained in:
Jan Bader 2023-12-06 16:43:27 +01:00
parent 6f5eb6a1ca
commit 65ce046585

View File

@ -9,6 +9,8 @@ import (
"runtime/pprof" "runtime/pprof"
"sync" "sync"
"slices"
"github.com/steakknife/hamming" "github.com/steakknife/hamming"
"github.com/vbauerster/mpb/v7" "github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor" "github.com/vbauerster/mpb/v7/decor"
@ -188,19 +190,18 @@ func main() {
for len(filesMap.Images) > 0 { for len(filesMap.Images) > 0 {
file := filesMap.Images[0] file := filesMap.Images[0]
newLength := len(filesMap.Images) - 1 filesMap.Images = slices.Delete(filesMap.Images, 0, 1)
filesMap.Images[0] = filesMap.Images[newLength]
filesMap.Images = filesMap.Images[:newLength]
var currentCluster []imageEntry var currentCluster []imageEntry
currentCluster = append(currentCluster, file) currentCluster = append(currentCluster, file)
for otherIndex := range filesMap.Images { for otherIndex := len(filesMap.Images) - 1; otherIndex >= 0; otherIndex-- {
otherFile := filesMap.Images[otherIndex] otherFile := filesMap.Images[otherIndex]
var distance = hamming.Uint64(file.imageHash, otherFile.imageHash) var distance = hamming.Uint64(file.imageHash, otherFile.imageHash)
if distance > 5 { if distance > 5 {
continue continue
} }
filesMap.Images = slices.Delete(filesMap.Images, otherIndex, otherIndex+1)
if len(currentCluster) == 1 { if len(currentCluster) == 1 {
fmt.Println(currentCluster[0].path) fmt.Println(currentCluster[0].path)
countDupeSets++ countDupeSets++