Package it.unimi.dsi.util
Class LongInterval
-
- All Implemented Interfaces:
LongBidirectionalIterable,LongCollection,LongIterable,LongSet,LongSortedSet,Serializable,Cloneable,Iterable<Long>,Collection<Long>,Set<Long>,SortedSet<Long>
public final class LongInterval extends AbstractLongSortedSet implements LongSortedSet, Serializable
An interval of longs. SeeIntervalfor details.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLongInterval(long left, long right)Builds an interval with given extremes.
-
Method Summary
Modifier and Type Method Description LongComparatorcomparator()intcompareTo(int x)Compares this interval to an integer.intcompareTo(int x, int radius)Compares this interval to an integer with a specified radius.intcompareTo(int x, int leftRadius, int rightRadius)Compares this interval to an integer with specified left and right radii.booleancontains(int x)Checks whether this interval contains the specified integer.booleancontains(int x, int radius)Checks whether this interval would contain the specified integer if enlarged in both directions by the specified radius.booleancontains(int x, int leftRadius, int rightRadius)Checks whether this interval would contain the specified integer if enlarged in each direction with the respective radius.booleancontains(LongInterval interval)Checks whether this interval contains the specified interval.booleanequals(Object o)Checks whether this interval is equal to another set of integers.longfirstLong()inthashCode()LongSortedSetheadSet(long to)LongBidirectionalIteratoriterator()Returns an iterator over the integers in this interval.LongBidirectionalIteratoriterator(long from)Returns an iterator over the integers in this interval larger than or equal to a given integer.longlastLong()longlength()Returns the interval length, that is, the number of integers contained in the interval.intsize()An alias forlength()miminised withInteger.MAX_VALUE.longsize64()An alias forlength().LongSortedSetsubSet(long from, long to)LongSortedSettailSet(long from)StringtoString()static LongIntervalvalueOf(long point)Returns a one-point interval.static LongIntervalvalueOf(long left, long right)Returns an interval with given extremes.-
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongSet
rem, remove
-
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, add, addAll, contains, contains, containsAll, remove, removeAll, retainAll, toArray, toLongArray, toLongArray
-
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongCollection
add, addAll, contains, containsAll, removeAll, removeIf, removeIf, retainAll, toArray, toLongArray, toLongArray
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongIterable
forEach, forEach
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongSet
add, contains, rem, remove, remove
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongSortedSet
first, headSet, last, 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
spliterator
-
-
-
-
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_INTERVALinstead.- 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_INTERVALinstead.- 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_INTERVALinstead.- 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:
sizein interfaceCollection<Long>- Specified by:
sizein interfaceSet<Long>- Specified by:
sizein classAbstractCollection<Long>- Returns:
- the interval length minimised with
Integer.MAX_VALUE.
-
size64
public long size64()
An alias forlength().- Returns:
- the interval length.
-
iterator
public LongBidirectionalIterator iterator()
Returns an iterator over the integers in this interval.- Specified by:
iteratorin interfaceCollection<Long>- Specified by:
iteratorin interfaceIterable<Long>- Specified by:
iteratorin interfaceLongBidirectionalIterable- Specified by:
iteratorin interfaceLongCollection- Specified by:
iteratorin interfaceLongIterable- Specified by:
iteratorin interfaceLongSet- Specified by:
iteratorin interfaceLongSortedSet- Specified by:
iteratorin interfaceSet<Long>- Specified by:
iteratorin classAbstractLongSortedSet- Returns:
- an integer iterator over the elements in this interval.
-
iterator
public LongBidirectionalIterator iterator(long from)
Returns an iterator over the integers in this interval larger than or equal to a given integer.- Specified by:
iteratorin interfaceLongSortedSet- 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
xis positioned at the left, belongs, or is positioned to the right of this interval enlarged byleftRadiuson the left andrightRadiusin the right, that is, asx<left−leftRadius,left−leftRadius≤x≤right+rightRadiusorright+rightRadius<x.
-
comparator
public LongComparator comparator()
- Specified by:
comparatorin interfaceLongSortedSet- Specified by:
comparatorin interfaceSortedSet<Long>
-
headSet
public LongSortedSet headSet(long to)
- Specified by:
headSetin interfaceLongSortedSet
-
tailSet
public LongSortedSet tailSet(long from)
- Specified by:
tailSetin interfaceLongSortedSet
-
subSet
public LongSortedSet subSet(long from, long to)
- Specified by:
subSetin interfaceLongSortedSet
-
firstLong
public long firstLong()
- Specified by:
firstLongin interfaceLongSortedSet
-
lastLong
public long lastLong()
- Specified by:
lastLongin interfaceLongSortedSet
-
toString
public String toString()
- Overrides:
toStringin classAbstractLongCollection
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<Long>- Specified by:
hashCodein interfaceSet<Long>- Overrides:
hashCodein classAbstractLongSet
-
equals
public boolean equals(Object o)
Checks whether this interval is equal to another set of integers.- Specified by:
equalsin interfaceCollection<Long>- Specified by:
equalsin interfaceSet<Long>- Overrides:
equalsin classAbstractLongSet- Parameters:
o- an object.- Returns:
- true if
ois an ordered set of integer containing the same element of this interval in the same order, or ifois a set of integers containing the same elements of this interval.
-
-