feat: optimization

This commit is contained in:
sajadMRjl
2026-01-28 03:42:36 +03:30
parent 55d198a387
commit d48a7750cc
10 changed files with 299 additions and 60 deletions

36
internal/dedup/filter.go Normal file
View File

@@ -0,0 +1,36 @@
package dedup
import (
"fmt"
"sync"
)
type Filter struct {
seen map[string]struct{}
mu sync.RWMutex
}
func New() *Filter {
return &Filter{
seen: make(map[string]struct{}),
}
}
// Check returns true if the item is NEW (not seen before)
func (f *Filter) Seen(address string, port int) bool {
key := fmt.Sprintf("%s:%d", address, port)
f.mu.RLock()
_, exists := f.seen[key]
f.mu.RUnlock()
if exists {
return true
}
f.mu.Lock()
f.seen[key] = struct{}{}
f.mu.Unlock()
return false
}