Skip to content

Commit

Permalink
Add AddrCollection Copy()
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangel-nubla committed Dec 30, 2024
1 parent 81c3224 commit a62e2f0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion addr_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *AddrCollection) Equal(other *AddrCollection) bool {
return false
}

for addrKey, _ := range c.addresses {
for addrKey := range c.addresses {
if _, ok := other.addresses[addrKey]; !ok {
return false
}
Expand All @@ -78,6 +78,17 @@ func (c *AddrCollection) Equal(other *AddrCollection) bool {
return true
}

func (c *AddrCollection) Copy() *AddrCollection {
c.addressesMutex.RLock()
defer c.addressesMutex.RUnlock()

result := NewAddrCollection()
for _, addr := range c.addresses {
result.Enlist(addr)
}
return result
}

func (c *AddrCollection) FilterPrefix(prefix netip.Prefix) *AddrCollection {
c.addressesMutex.RLock()
defer c.addressesMutex.RUnlock()
Expand Down

0 comments on commit a62e2f0

Please sign in to comment.