View Source Guesswork.Constraint.Arithmetic.Range (Guesswork v0.8.0)

Indicates multiple possible integer values.

Negation

Because ranges are subsets of the denumerable integer set, it is possible to represent Not <range> as the complement of that range.

Enumerable

Because ranges can represent infinite sets you should be very careful when using the Enum module. In general, Stream is going to be a lot safer.

Summary

Functions

Adds all of the points in one range to all of the points of another.

Takes the complement of the set. Return nil for an empty range.

Inserts a single integer point into a range.

Inserts set of points into an existing range.

Checks if the range contains the integer.

Multiplies the range by an integer value.

Builds a new range that covers every possible integer.

Removes a single integer point from a range.

Removes a set of points from a range. Returns nil if the the set becomes empty.

Subtracts all of the points in one range to all of the points of another.

Types

elem()

@type elem() :: {point(), point()}

point()

@type point() :: :neg_inf | :pos_inf | integer()

t()

@type t() :: %Guesswork.Constraint.Arithmetic.Range{values: [elem(), ...]}

Functions

add(range1, range2)

@spec add(t(), t()) :: t()

Adds all of the points in one range to all of the points of another.

Examples

iex> r1 = Guesswork.Constraint.Arithmetic.Range.new(3, false)
...> r2 = Guesswork.Constraint.Arithmetic.Range.new(4, false)
...> Guesswork.Constraint.Arithmetic.Range.add(r1, r2)
%Guesswork.Constraint.Arithmetic.Range{values: [{7, 7}]}
iex> r1 = Guesswork.Constraint.Arithmetic.Range.new(3, false)
...> r2 = Guesswork.Constraint.Arithmetic.Range.new(4, 7, false)
...> Guesswork.Constraint.Arithmetic.Range.add(r1, r2)
%Guesswork.Constraint.Arithmetic.Range{values: [{7, 10}]}
iex> r1 = Guesswork.Constraint.Arithmetic.Range.new(3, :pos_inf, false)
...> r2 = Guesswork.Constraint.Arithmetic.Range.new(4, 7, false)
...> Guesswork.Constraint.Arithmetic.Range.add(r1, r2)
%Guesswork.Constraint.Arithmetic.Range{values: [{7, :pos_inf}]}

all_points?(arg1)

@spec all_points?(t()) :: boolean()

complement(range)

@spec complement(t()) :: t() | nil

Takes the complement of the set. Return nil for an empty range.

Examples

iex> %Guesswork.Constraint.Arithmetic.Range{values: []}
...> |> Guesswork.Constraint.Arithmetic.Range.complement()
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, :pos_inf}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(:neg_inf, :pos_inf, false)
...> |> Guesswork.Constraint.Arithmetic.Range.complement()
nil
iex> Guesswork.Constraint.Arithmetic.Range.new(:neg_inf, 4, false)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(7, :pos_inf)
...> |> Guesswork.Constraint.Arithmetic.Range.complement()
%Guesswork.Constraint.Arithmetic.Range{values: [{5, 6}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(-3, 4, false)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(7, 11)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(35, 98)
...> |> Guesswork.Constraint.Arithmetic.Range.complement()
%Guesswork.Constraint.Arithmetic.Range{
  values: [{:neg_inf, -4}, {5, 6}, {12, 34}, {99, :pos_inf}]
}

count(arg1)

@spec count(t()) :: :empty | {:point, integer()} | :multiple

insert(range, x)

@spec insert(t(), integer()) :: t()

Inserts a single integer point into a range.

Examples

iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(4)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, 1}, {4, 4}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, false)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(1)
%Guesswork.Constraint.Arithmetic.Range{values: [{1, :pos_inf}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(-11)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, 1}]}

insert(range, x, y)

@spec insert(t(), point(), point()) :: t()

Inserts set of points into an existing range.

Examples

iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(4, 2)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, 4}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, false)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(-1, 3)
%Guesswork.Constraint.Arithmetic.Range{values: [{-1, :pos_inf}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.insert(-11, :neg_inf)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, 1}]}

intersection(r1, r2)

@spec intersection(t(), t()) :: t() | nil

max(range)

@spec max(t()) :: point() | nil

member?(range, x)

@spec member?(t(), integer()) :: boolean()

Checks if the range contains the integer.

Examples

iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.member?(2)
false
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, false)
...> |> Guesswork.Constraint.Arithmetic.Range.member?(2)
true
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.member?(3)
false

min(range)

@spec min(t()) :: point() | nil

multiply_int(range, x)

@spec multiply_int(t(), integer()) :: t()

Multiplies the range by an integer value.

new()

@spec new() :: t() | nil

Builds a new range that covers every possible integer.

new(x, negated)

@spec new(integer() | [integer()], boolean()) :: t() | nil

new(x, y, negated)

@spec new(point(), point(), boolean()) :: t() | nil

point_greater_than?(p1, p2)

@spec point_greater_than?(point(), point()) :: boolean()

point_less_than?(p1, p2)

@spec point_less_than?(point(), point()) :: boolean()

remove(range, x)

@spec remove(t(), integer()) :: t()

Removes a single integer point from a range.

Examples

iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.remove(1)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, 0}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, false)
...> |> Guesswork.Constraint.Arithmetic.Range.remove(2)
%Guesswork.Constraint.Arithmetic.Range{values: [{3, :pos_inf}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.remove(-4)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, -5}, {-3, 1}]}

remove(range, x, y)

@spec remove(t(), point(), point()) :: t() | nil

Removes a set of points from a range. Returns nil if the the set becomes empty.

Examples

iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.remove(:neg_inf, 1)
nil
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, false)
...> |> Guesswork.Constraint.Arithmetic.Range.remove(:neg_inf, 4)
%Guesswork.Constraint.Arithmetic.Range{values: [{5, :pos_inf}]}
iex> Guesswork.Constraint.Arithmetic.Range.new(2, :pos_inf, true)
...> |> Guesswork.Constraint.Arithmetic.Range.remove(-8, -4)
%Guesswork.Constraint.Arithmetic.Range{values: [{:neg_inf, -9}, {-3, 1}]}

subtract(range1, range2)

@spec subtract(t(), t()) :: t()

Subtracts all of the points in one range to all of the points of another.

Examples

iex> r1 = Guesswork.Constraint.Arithmetic.Range.new(3, false)
...> r2 = Guesswork.Constraint.Arithmetic.Range.new(4, false)
...> Guesswork.Constraint.Arithmetic.Range.subtract(r1, r2)
%Guesswork.Constraint.Arithmetic.Range{values: [{-1, -1}]}
iex> r1 = Guesswork.Constraint.Arithmetic.Range.new(3, false)
...> r2 = Guesswork.Constraint.Arithmetic.Range.new(4, 7, false)
...> Guesswork.Constraint.Arithmetic.Range.subtract(r2, r1)
%Guesswork.Constraint.Arithmetic.Range{values: [{1, 4}]}
iex> r1 = Guesswork.Constraint.Arithmetic.Range.new(3, :pos_inf, false)
...> r2 = Guesswork.Constraint.Arithmetic.Range.new(4, 7, false)
...> Guesswork.Constraint.Arithmetic.Range.subtract(r1, r2)
%Guesswork.Constraint.Arithmetic.Range{values: [{-4, :pos_inf}]}

union(range, acc)

@spec union(t(), t()) :: t()