Skip to content

fix: supernet_for uses mask intersection instead of common prefix#16

Merged
3Hren merged 1 commit intomainfrom
fix/supernet_for
Apr 7, 2026
Merged

fix: supernet_for uses mask intersection instead of common prefix#16
3Hren merged 1 commit intomainfrom
fix/supernet_for

Conversation

@3Hren
Copy link
Copy Markdown
Member

@3Hren 3Hren commented Apr 7, 2026

The old algorithm only compared base addresses to find a common prefix, ignoring input masks entirely. This produced incorrect results when inputs had different prefix lengths (e.g. /24 and /16 with the same base address returned /24 instead of /16).

New algorithm — intersects masks and clears bits where addresses disagree, yielding the tightest valid supernet.

Unfortunately, this fix resulted in many tests broken. Several existing tests expected the old (wider) supernet values. These were not catching the bug — they simply matched the previous lossy behavior and have been updated to reflect the correct tighter results.

Also fixes binary_split to fold supernet_for over all window elements instead of just the endpoints, since the tighter supernet no longer guarantees contiguous address coverage.

The old algorithm only compared base addresses to find a common prefix,
ignoring input masks entirely. This produced incorrect results when
inputs had different prefix lengths (e.g. /24 and /16 with the same
base address returned /24 instead of /16).

New algorithm — intersects masks and clears bits where addresses
disagree, yielding the tightest valid supernet.

Unfortunately, this fix resulted in many tests broken. Several
existing tests expected the old (wider) supernet values. These
were not catching the bug — they simply matched the previous lossy
behavior and have been updated to reflect the correct tighter results.

Also fixes binary_split to fold supernet_for over all window elements
instead of just the endpoints, since the tighter supernet no longer
guarantees contiguous address coverage.
@3Hren 3Hren merged commit 4af1608 into main Apr 7, 2026
4 checks passed
@3Hren 3Hren deleted the fix/supernet_for branch April 7, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant