cidrv6Merge(cidrs: readonly Cidrv6[]): Cidrv6[]
Merges IPv6 CIDR blocks into the minimal covering set.
Takes an array of possibly overlapping, adjacent, or redundant CIDR blocks and returns the minimal set of non-overlapping CIDR prefix blocks covering the exact same address space.
The result matches the dialect of the inputs. When they disagree, it is in MaskedCidrv6 form (ADR 0006).
Compact adjacent allocations
Compact adjacent allocations
import { assertEquals } from "@std/assert"; import { cidrv6Merge, parseCidrv6, stringifyCidrv6 } from "@hertzg/ip/cidrv6"; const blocks = [ parseCidrv6("2001:db8::/33"), parseCidrv6("2001:db8:8000::/33"), ]; assertEquals(cidrv6Merge(blocks).map(stringifyCidrv6), ["2001:db8::/32"]);
Remove contained and merge siblings
Remove contained and merge siblings
import { assertEquals } from "@std/assert"; import { cidrv6Merge, parseCidrv6, stringifyCidrv6 } from "@hertzg/ip/cidrv6"; const blocks = [ parseCidrv6("2001:db8::/32"), parseCidrv6("2001:db8:1::/48"), ]; assertEquals(cidrv6Merge(blocks).map(stringifyCidrv6), ["2001:db8::/32"]);
Masked blocks merge to masked blocks
Masked blocks merge to masked blocks
import { assertEquals } from "@std/assert"; import { cidrv6Merge, stringifyCidrv6 } from "@hertzg/ip/cidrv6"; const mask = 0xFFFFFFFF800000000000000000000000n; const halves = [ { address: 0x20010db8n << 96n, mask }, { address: 0x20010db88000n << 80n, mask }, ]; assertEquals(cidrv6Merge(halves).map(stringifyCidrv6), ["2001:db8::/ffff:ffff::"]);
cidrs: readonly Cidrv6[]
The CIDR blocks to merge
Cidrv6[]
Minimal set of non-overlapping CIDR blocks, sorted by address