aromatt / netipds

Immutable, tree-based map and set types for net/netip
MIT License
3 stars 0 forks source link

Add PrefixSet.PrefixSeq and PrefixSet.PrefixCompactSeq for Go 1.23+ #12

Open database64128 opened 1 week ago

database64128 commented 1 week ago

Serializing large prefix sets will become much more efficient, if we can avoid allocating the intermediate slice by allowing iterator access over the prefixes. I propose we add:

func (s *PrefixSet) PrefixSeq() iter.Seq[netip.Prefix]
func (s *PrefixSet) PrefixCompactSeq() iter.Seq[netip.Prefix]

Alternatively, give the existing Prefixes and PrefixesCompact names to the new iterator methods, to align with the naming conventions.

I'd be happy to work on this and open a PR.

Related proposal at netipx: go4org/netipx#21

aromatt commented 1 week ago

Hi @database64128, thanks for filing this issue. Iterators are definitely on my roadmap for this library. A PR would be much appreciated, if you're up for it.

I'll get back to you about naming (and I'm open to further discussion about it). Relevant context: I have made an effort to mirror the naming patterns of netipx wherever it makes sense. While not perfect, this is part of an explicit goal of netipds to fit in with netip/netipx.