Struct LongInterval
- Namespace
- ICSharpCode.Decompiler.Util
- Assembly
- ICSharpCode.Decompiler.dll
Represents a half-closed interval. The start position is inclusive; but the end position is exclusive.
public struct LongInterval : IEquatable<LongInterval>
- Implements
- Inherited Members
Remarks
Start <= unchecked(End - 1): normal interval Start == End: empty interval Special case: Start == End == long.MinValue: interval containing all integers, not an empty interval!
Constructors
LongInterval(long, long)
Creates a new interval.
public LongInterval(long start, long end)
Parameters
start
longStart position (inclusive)
end
longEnd position (exclusive). Note that it is possible to create an interval that includes long.MaxValue by using end==long.MaxValue+1==long.MinValue.
Remarks
This method can be used to create an empty interval by specifying start==end, however this is error-prone due to the special case of start==end==long.MinValue being interpreted as the full interval [long.MinValue,long.MaxValue].
Fields
End
Gets the exclusive end of the interval.
public readonly long End
Field Value
Remarks
Note that an End of long.MinValue is a special case, and stands for an actual End of long.MaxValue+1. If possible, prefer using InclusiveEnd for comparisons, as that does not have an overflow problem.
Start
Gets the inclusive start of the interval.
public readonly long Start
Field Value
Properties
InclusiveEnd
Gets the inclusive end of the interval. (End - 1) For empty intervals, this returns Start - 1.
public long InclusiveEnd { get; }
Property Value
Remarks
Because there is no empty interval at int.MinValue, (Start==End==int.MinValue is a special case referring to [int.MinValue..int.MaxValue]), integer overflow is not a problem here.
IsEmpty
public bool IsEmpty { get; }
Property Value
Methods
Contains(long)
public bool Contains(long val)
Parameters
val
long
Returns
Equals(LongInterval)
public bool Equals(LongInterval other)
Parameters
other
LongInterval
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
GetHashCode()
public override int GetHashCode()
Returns
Inclusive(long, long)
Creates a new interval from start to end. Unlike the constructor where the end position is exclusive, this method interprets the end position as inclusive.
This method cannot be used to construct an empty interval.
public static LongInterval Inclusive(long start, long inclusiveEnd)
Parameters
Returns
Intersect(LongInterval)
Calculates the intersection between this interval and the other interval.
public LongInterval Intersect(LongInterval other)
Parameters
other
LongInterval
Returns
Range()
Returns an enumerator over all values in this interval.
public IEnumerable<long> Range()
Returns
ToString()
public override string ToString()
Returns
Operators
operator ==(LongInterval, LongInterval)
public static bool operator ==(LongInterval lhs, LongInterval rhs)
Parameters
lhs
LongIntervalrhs
LongInterval
Returns
operator !=(LongInterval, LongInterval)
public static bool operator !=(LongInterval lhs, LongInterval rhs)
Parameters
lhs
LongIntervalrhs
LongInterval