RangeSet (range_set v1.0.0)

Summary

Functions

Determines if the set is continuous (there are no gaps).

Returns difference between sets.

Determines if set is empty.

Returns set that contains all gaps needed to make the range continuous.

Returns intersection between two sets

Computes length of the all ranges combined, aka amount of unique integers in set.

Create new empty set.

Adds new value to set.

Returns list of values stored in set.

Returns union of sets

Types

@opaque ranges()
@type t() :: %RangeSet{ranges: ranges()}

Functions

Link to this function

continuous?(range_set)

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

Determines if the set is continuous (there are no gaps).

Link to this function

difference(range_set, other)

@spec difference(t(), t() | integer() | Range.t() | [integer()]) :: t()

Returns difference between sets.

Link to this function

empty?(range_set)

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

Determines if set is empty.

iex> RangeSet.empty?(RangeSet.new())
true
iex> RangeSet.empty?(RangeSet.new(1..10))
false
Link to this function

gaps(range_set)

@spec gaps(t()) :: t()

Returns set that contains all gaps needed to make the range continuous.

iex> RangeSet.new([0..2, 6..9]) |> RangeSet.gaps()
RangeSet.new([3..5])

iex> RangeSet.new([0..5, 6..9]) |> RangeSet.gaps()
RangeSet.new([])
Link to this function

intersection(range_set1, range_set2)

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

Returns intersection between two sets

Link to this function

length(range_set)

@spec length(t()) :: non_neg_integer()

Computes length of the all ranges combined, aka amount of unique integers in set.

Link to this function

max(range_set, empty_callback \\ fn -> raise Enum.EmptyError end)

@spec max(t(), (-> term())) :: integer() | term()

Returns the maximal element in set.

If set is empty, the provided empty_callback is called.

Examples

iex> RangeSet.max(RangeSet.new([1..2, 5..10]))
10
Link to this function

member?(range_set, value)

@spec member?(t(), integer()) :: boolean()
Link to this function

min(range_set, empty_callback \\ fn -> raise Enum.EmptyError end)

@spec min(t(), (-> term())) :: integer() | term()

Returns the minimal element in set.

If set is empty, the provided empty_callback is called.

Examples

iex> RangeSet.min(RangeSet.new([1..2, 5..10]))
1
@spec new() :: t()

Create new empty set.

@spec new(Range.t()) :: t()
@spec new(Enumerable.t(Range.t())) :: t()
Link to this function

put(range_set, value)

@spec put(t(), integer() | Range.t()) :: t()

Adds new value to set.

Link to this function

to_list(range_set)

@spec to_list(t()) :: [integer()]

Returns list of values stored in set.

Link to this function

union(range_set1, range_set2)

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

Returns union of sets