Package it.unimi.dsi.util
Class Interval
java.lang.Object
java.util.AbstractCollection<Integer>
it.unimi.dsi.fastutil.ints.AbstractIntCollection
it.unimi.dsi.fastutil.ints.AbstractIntSet
it.unimi.dsi.fastutil.ints.AbstractIntSortedSet
it.unimi.dsi.util.Interval
- All Implemented Interfaces:
it.unimi.dsi.fastutil.ints.IntBidirectionalIterable
,it.unimi.dsi.fastutil.ints.IntCollection
,it.unimi.dsi.fastutil.ints.IntIterable
,it.unimi.dsi.fastutil.ints.IntSet
,it.unimi.dsi.fastutil.ints.IntSortedSet
,Serializable
,Cloneable
,Iterable<Integer>
,Collection<Integer>
,SequencedCollection<Integer>
,SequencedSet<Integer>
,Set<Integer>
,SortedSet<Integer>
public final class Interval
extends it.unimi.dsi.fastutil.ints.AbstractIntSortedSet
implements it.unimi.dsi.fastutil.ints.IntSortedSet, Serializable
An interval of integers. An interval is defined
by two integers, called its
left
and right
extremes, and contains all integers x such that
left
≤ x ≤ right
.
This class has no constructor: use the static factory methods
valueOf(int, int)
and valueOf(int)
, instead.
Instances of this class are immutable, and moreover implement
the IntSortedSet
interface. The
equality method allows to check equality with
both sorted and non-sorted sets of integers.
To reduce garbage collection, intervals made of one non-negative small points are precomputed and returned upon request.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Interval
(int left, int right) Builds an interval with given extremes. -
Method Summary
Modifier and TypeMethodDescriptionit.unimi.dsi.fastutil.ints.IntComparator
int
compareTo
(int x) Compares this interval to an integer.int
compareTo
(int x, int radius) Compares this interval to an integer with a specified radius.int
compareTo
(int x, int leftRadius, int rightRadius) Compares this interval to an integer with specified left and right radii.boolean
contains
(int x) Checks whether this interval contains the specified integer.boolean
contains
(int x, int radius) Checks whether this interval would contain the specified integer if enlarged in both directions by the specified radius.boolean
contains
(int x, int leftRadius, int rightRadius) Checks whether this interval would contain the specified integer if enlarged in each direction with the respective radius.boolean
Checks whether this interval contains the specified interval.boolean
Checks whether this interval is equal to another set of integers.int
firstInt()
int
hashCode()
it.unimi.dsi.fastutil.ints.IntSortedSet
headSet
(int to) it.unimi.dsi.fastutil.ints.IntBidirectionalIterator
iterator()
Returns an iterator over the integers in this interval.it.unimi.dsi.fastutil.ints.IntBidirectionalIterator
iterator
(int from) Returns an iterator over the integers in this interval larger than or equal to a given integer.int
lastInt()
int
length()
Returns the interval length, that is, the number of integers contained in the interval.int
size()
An alias forlength()
.it.unimi.dsi.fastutil.ints.IntSortedSet
subSet
(int from, int to) it.unimi.dsi.fastutil.ints.IntSortedSet
tailSet
(int from) toString()
static Interval
valueOf
(int point) Returns a one-point interval.static Interval
valueOf
(int left, int right) Returns an interval with given extremes.Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntSet
rem, remove
Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntCollection
add, add, addAll, addAll, contains, containsAll, containsAll, forEach, remove, removeAll, removeAll, removeIf, retainAll, retainAll, toArray, toIntArray, toIntArray
Methods inherited from class java.util.AbstractCollection
clear, isEmpty, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
toArray
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntCollection
add, addAll, containsAll, intIterator, intParallelStream, intSpliterator, intStream, parallelStream, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toArray, toIntArray, toIntArray
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterable
forEach, forEach, forEach
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntSet
add, contains, rem, remove, remove
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntSortedSet
first, headSet, last, spliterator, subSet, tailSet
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from interface java.util.SortedSet
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed
-
Field Details
-
left
public final int leftThe left extreme of the interval. -
right
public final int rightThe right extreme of the interval.
-
-
Constructor Details
-
Interval
protected Interval(int left, int right) Builds an interval with given extremes.You cannot generate an empty interval with this constructor. Use
Intervals.EMPTY_INTERVAL
instead.- Parameters:
left
- the left extreme.right
- the right extreme (which must be greater than or equal to the left extreme).
-
-
Method Details
-
valueOf
Returns an interval with given extremes.You cannot obtain an empty interval with this factory method. Use
Intervals.EMPTY_INTERVAL
instead.- Parameters:
left
- the left extreme.right
- the right extreme (which must be greater than or equal to the left extreme).- Returns:
- an interval with the given extremes.
-
valueOf
Returns a one-point interval.You cannot obtain an empty interval with this factory method. Use
Intervals.EMPTY_INTERVAL
instead.- Parameters:
point
- a point.- Returns:
- a one-point interval
-
length
public int length()Returns the interval length, that is, the number of integers contained in the interval.- Returns:
- the interval length.
-
size
public int size()An alias forlength()
.- Specified by:
size
in interfaceCollection<Integer>
- Specified by:
size
in interfaceSet<Integer>
- Specified by:
size
in classAbstractCollection<Integer>
- Returns:
- the interval length.
-
iterator
public it.unimi.dsi.fastutil.ints.IntBidirectionalIterator iterator()Returns an iterator over the integers in this interval.- Specified by:
iterator
in interfaceCollection<Integer>
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.ints.IntBidirectionalIterable
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.ints.IntCollection
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.ints.IntIterable
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.ints.IntSet
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
- Specified by:
iterator
in interfaceIterable<Integer>
- Specified by:
iterator
in interfaceSet<Integer>
- Specified by:
iterator
in classit.unimi.dsi.fastutil.ints.AbstractIntSortedSet
- Returns:
- an integer iterator over the elements in this interval.
-
iterator
public it.unimi.dsi.fastutil.ints.IntBidirectionalIterator iterator(int from) Returns an iterator over the integers in this interval larger than or equal to a given integer.- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
- Parameters:
from
- the starting integer.- Returns:
- an integer iterator over the elements in this interval.
-
contains
public boolean contains(int x) Checks whether this interval contains the specified integer. -
contains
Checks whether this interval contains the specified interval.- Parameters:
interval
- an interval.- Returns:
- whether this interval contains (as a set)
interval
.
-
contains
public boolean contains(int x, int radius) Checks whether this interval would contain the specified integer if enlarged in both directions by the specified radius. -
contains
public boolean contains(int x, int leftRadius, int rightRadius) Checks whether this interval would contain the specified integer if enlarged in each direction with the respective radius. directions by the specified radius. -
compareTo
public int compareTo(int x) Compares this interval to an integer. -
compareTo
public int compareTo(int x, int radius) Compares this interval to an integer with a specified radius. -
compareTo
public int compareTo(int x, int leftRadius, int rightRadius) Compares this interval to an integer with specified left and right radii.- Parameters:
x
- an integer.leftRadius
- the left radius.rightRadius
- the right radius.- Returns:
- a negative integer, zero, or a positive integer as
x
is positioned at the left, belongs, or is positioned to the right of this interval enlarged byleftRadius
on the left andrightRadius
in the right, that is, asx
<left
−leftRadius
,left
−leftRadius
≤x
≤right
+rightRadius
orright
+rightRadius
<x
.
-
comparator
public it.unimi.dsi.fastutil.ints.IntComparator comparator()- Specified by:
comparator
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
- Specified by:
comparator
in interfaceSortedSet<Integer>
-
headSet
public it.unimi.dsi.fastutil.ints.IntSortedSet headSet(int to) - Specified by:
headSet
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
-
tailSet
public it.unimi.dsi.fastutil.ints.IntSortedSet tailSet(int from) - Specified by:
tailSet
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
-
subSet
public it.unimi.dsi.fastutil.ints.IntSortedSet subSet(int from, int to) - Specified by:
subSet
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
-
firstInt
public int firstInt()- Specified by:
firstInt
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
-
lastInt
public int lastInt()- Specified by:
lastInt
in interfaceit.unimi.dsi.fastutil.ints.IntSortedSet
-
toString
- Overrides:
toString
in classit.unimi.dsi.fastutil.ints.AbstractIntCollection
-
hashCode
public int hashCode() -
equals
Checks whether this interval is equal to another set of integers.- Specified by:
equals
in interfaceCollection<Integer>
- Specified by:
equals
in interfaceSet<Integer>
- Overrides:
equals
in classit.unimi.dsi.fastutil.ints.AbstractIntSet
- Parameters:
o
- an object.- Returns:
- true if
o
is an ordered set of integer containing the same element of this interval in the same order, or ifo
is a set of integers containing the same elements of this interval.
-