Pfx.contrast

You're seeing just the function contrast, go back to Pfx module for more information.

Specs

contrast(prefix(), prefix()) ::
  :equal
  | :more
  | :less
  | :left
  | :right
  | :disjoint
  | :left_nc
  | :right_nc
  | :incompatible
  | :einvalid

Contrasts pfx1 to pfx2.

Contrasting two prefixes yields one of:

  • :equal pfx1 is equal to pfx2
  • :more pfx1 is more specific and contained in pfx2
  • :less pfx1 is less specific and contains pfx2
  • :left pfx1 is left-adjacent to pfx2 such that it can be combined with pfx2
  • :left_nc pfx1 is left-adjacent to pfx2, but cannot be combined
  • :right pfx1 is right-adjacent to pfx2 such that is can be combined with pfx2
  • :right_nc pfx1 is right-adjacent to pfx2, but cannot be combined
  • :disjoint pfx1 has no match with pfx2
  • :einvalid either pfx1 or pfx2 was invalid
  • :incompatible pfx1 and pfx2 donot have the same maxlen

Examples

iex> contrast("10.10.0.0/16", "10.10.0.0/16")
:equal

iex> contrast("10.10.10.0/24", "10.10.0.0/16")
:more

iex> contrast("10.0.0.0/8", "10.255.255.0/24")
:less

# can be combined as 1.1.0.0/23
iex> contrast("1.1.0.0/24", "1.1.1.0/24")
:left

# can be combined as 1.1.0.0/23
iex> contrast("1.1.1.0/24", "1.1.0.0/24")
:right

# adjacent, but cannot be combined
iex> contrast("1.1.3.0/24", "1.1.4.0/25")
:left_nc

# adjacent, but cannot be combined
iex> contrast("1.1.4.0/25", "1.1.3.0/24")
:right_nc

# adjacent again, but cannot be combined
iex> contrast("1.1.1.0/24", "1.1.2.0/24")
:left_nc

# adjacent again, but cannot be combined
iex> contrast("1.1.2.0/24", "1.1.1.0/24")
:right_nc

iex> contrast("1.2.3.4/30", "1.2.3.12/30")
:disjoint

iex> contrast("10.10.0.0/16", %Pfx{bits: <<10,12>>, maxlen: 32})
:disjoint

iex> contrast("1.2.3.4", {1, 2, 3, 4})
:equal

iex> contrast("1.1.1.1", "acdc:1976::1")
:incompatible

iex> contrast("1.1.1.400", "1.1.1.1")
:einvalid