mirror of
https://github.com/SajadMRjl/find-me-internet.git
synced 2026-07-19 08:46:26 +00:00
feat: optimization
This commit is contained in:
36
internal/dedup/filter.go
Normal file
36
internal/dedup/filter.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user