Package it.unimi.dsi.util
Class LongInterval
- java.lang.Object
-
- java.util.AbstractCollection<java.lang.Long>
-
- it.unimi.dsi.fastutil.longs.AbstractLongCollection
-
- it.unimi.dsi.fastutil.longs.AbstractLongSet
-
- it.unimi.dsi.fastutil.longs.AbstractLongSortedSet
-
- it.unimi.dsi.util.LongInterval
-
- All Implemented Interfaces:
it.unimi.dsi.fastutil.longs.LongBidirectionalIterable
,it.unimi.dsi.fastutil.longs.LongCollection
,it.unimi.dsi.fastutil.longs.LongIterable
,it.unimi.dsi.fastutil.longs.LongSet
,it.unimi.dsi.fastutil.longs.LongSortedSet
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<java.lang.Long>
,java.util.Collection<java.lang.Long>
,java.util.Set<java.lang.Long>
,java.util.SortedSet<java.lang.Long>
public final class LongInterval extends it.unimi.dsi.fastutil.longs.AbstractLongSortedSet implements it.unimi.dsi.fastutil.longs.LongSortedSet, java.io.Serializable
An interval of longs. SeeInterval
for details.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LongInterval(long left, long right)
Builds an interval with given extremes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description it.unimi.dsi.fastutil.longs.LongComparator
comparator()
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
contains(LongInterval interval)
Checks whether this interval contains the specified interval.boolean
equals(java.lang.Object o)
Checks whether this interval is equal to another set of integers.long
firstLong()
int
hashCode()
it.unimi.dsi.fastutil.longs.LongSortedSet
headSet(long to)
it.unimi.dsi.fastutil.longs.LongBidirectionalIterator
iterator()
Returns an iterator over the integers in this interval.it.unimi.dsi.fastutil.longs.LongBidirectionalIterator
iterator(long from)
Returns an iterator over the integers in this interval larger than or equal to a given integer.long
lastLong()
long
length()
Returns the interval length, that is, the number of integers contained in the interval.int
size()
An alias forlength()
miminised withInteger.MAX_VALUE
.long
size64()
An alias forlength()
.it.unimi.dsi.fastutil.longs.LongSortedSet
subSet(long from, long to)
it.unimi.dsi.fastutil.longs.LongSortedSet
tailSet(long from)
java.lang.String
toString()
static LongInterval
valueOf(long point)
Returns a one-point interval.static LongInterval
valueOf(long left, long right)
Returns an interval with given extremes.-
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, add, addAll, addAll, contains, contains, containsAll, containsAll, forEach, remove, removeAll, removeAll, removeIf, retainAll, retainAll, toArray, toLongArray, toLongArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongCollection
add, addAll, contains, containsAll, longIterator, longParallelStream, longSpliterator, longStream, parallelStream, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toArray, toLongArray, toLongArray
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongSet
add, contains, rem, remove, remove
-
-
-
-
Constructor Detail
-
LongInterval
protected LongInterval(long left, long 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 Detail
-
valueOf
public static LongInterval valueOf(long left, long right)
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
public static LongInterval valueOf(long point)
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 long 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()
miminised withInteger.MAX_VALUE
.- Specified by:
size
in interfacejava.util.Collection<java.lang.Long>
- Specified by:
size
in interfacejava.util.Set<java.lang.Long>
- Specified by:
size
in classjava.util.AbstractCollection<java.lang.Long>
- Returns:
- the interval length minimised with
Integer.MAX_VALUE
.
-
size64
public long size64()
An alias forlength()
.- Returns:
- the interval length.
-
iterator
public it.unimi.dsi.fastutil.longs.LongBidirectionalIterator iterator()
Returns an iterator over the integers in this interval.- Specified by:
iterator
in interfacejava.util.Collection<java.lang.Long>
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Long>
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.longs.LongBidirectionalIterable
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.longs.LongCollection
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.longs.LongIterable
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.longs.LongSet
- Specified by:
iterator
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
- Specified by:
iterator
in interfacejava.util.Set<java.lang.Long>
- Specified by:
iterator
in classit.unimi.dsi.fastutil.longs.AbstractLongSortedSet
- Returns:
- an integer iterator over the elements in this interval.
-
iterator
public it.unimi.dsi.fastutil.longs.LongBidirectionalIterator iterator(long 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.longs.LongSortedSet
- 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
public boolean contains(LongInterval interval)
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.longs.LongComparator comparator()
- Specified by:
comparator
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
- Specified by:
comparator
in interfacejava.util.SortedSet<java.lang.Long>
-
headSet
public it.unimi.dsi.fastutil.longs.LongSortedSet headSet(long to)
- Specified by:
headSet
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
-
tailSet
public it.unimi.dsi.fastutil.longs.LongSortedSet tailSet(long from)
- Specified by:
tailSet
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
-
subSet
public it.unimi.dsi.fastutil.longs.LongSortedSet subSet(long from, long to)
- Specified by:
subSet
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
-
firstLong
public long firstLong()
- Specified by:
firstLong
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
-
lastLong
public long lastLong()
- Specified by:
lastLong
in interfaceit.unimi.dsi.fastutil.longs.LongSortedSet
-
toString
public java.lang.String toString()
- Overrides:
toString
in classit.unimi.dsi.fastutil.longs.AbstractLongCollection
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<java.lang.Long>
- Specified by:
hashCode
in interfacejava.util.Set<java.lang.Long>
- Overrides:
hashCode
in classit.unimi.dsi.fastutil.longs.AbstractLongSet
-
equals
public boolean equals(java.lang.Object o)
Checks whether this interval is equal to another set of integers.- Specified by:
equals
in interfacejava.util.Collection<java.lang.Long>
- Specified by:
equals
in interfacejava.util.Set<java.lang.Long>
- Overrides:
equals
in classit.unimi.dsi.fastutil.longs.AbstractLongSet
- 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.
-
-