From 7d015ba28edcf835256422d384988b059ed4bc5c Mon Sep 17 00:00:00 2001 From: Karl Gaissmaier Date: Sat, 30 Jul 2022 19:06:00 +0200 Subject: [PATCH] bump required version --- go.mod | 2 +- go.sum | 2 ++ iprange.go | 17 ++++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 4b33d94..4e9c9b6 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/gaissmai/iprange go 1.18 -require github.com/gaissmai/extnetip v0.2.0 +require github.com/gaissmai/extnetip v0.3.0 diff --git a/go.sum b/go.sum index 2361c8e..87174a7 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/gaissmai/extnetip v0.2.0 h1:m9BAcG3RbEyGsWmC6RCBgH7HOttPgeIMZFZsJoqt+30= github.com/gaissmai/extnetip v0.2.0/go.mod h1:M3NWlyFKaVosQXWXKKeIPK+5VM4U85DahdIqNYX4TK4= +github.com/gaissmai/extnetip v0.3.0 h1:JNCEMbKAb9tE3SthpAmikPVuR2ifyQt5IKt30RyCSxE= +github.com/gaissmai/extnetip v0.3.0/go.mod h1:M3NWlyFKaVosQXWXKKeIPK+5VM4U85DahdIqNYX4TK4= diff --git a/iprange.go b/iprange.go index 22d69d8..2a818f0 100644 --- a/iprange.go +++ b/iprange.go @@ -151,7 +151,7 @@ func (r IPRange) Prefixes() []netip.Prefix { // // It appends to dst the netip.Prefix entries that covers r. func (r IPRange) PrefixesAppend(dst []netip.Prefix) []netip.Prefix { - return extnetip.AppendPrefixes(dst, r.first, r.last) + return extnetip.PrefixesAppend(dst, r.first, r.last) } // String returns the string form of the IPRange. @@ -208,12 +208,15 @@ func Merge(in []IPRange) (out []IPRange) { case topic.isDisjunctLeft(r): // disjoint [f...l] [f...l] out = append(out, r) + case topic.covers(r): + // no-op + continue case topic.last.Less(r.last): // partial overlap [f......l] - // [f....l] + // [f....l] topic.last = r.last default: - // no-op: covers or equal + panic("unreachable") } } @@ -254,18 +257,18 @@ func (r IPRange) Remove(in []IPRange) (out []IPRange) { // left overlap, move cursor r.first = m.last.Next() case m.first.Compare(r.first) > 0: - // right overlap, save [r.first, d.first-1) + // right overlap, save [r.first, m.first-1) out = append(out, IPRange{r.first, m.first.Prev()}) - // new r, (d.last, r.last] + // new r first r.first = m.last.Next() default: panic("unreachable") } - // overflow from d.last.Next() + // test for overflow from last.Next() if !r.first.IsValid() { return out } - // cursor moved behind r.last + // test if cursor moved behind r.last if r.last.Less(r.first) { return out }