Table of Contents

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 long

Start position (inclusive)

end long

End 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

long

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

long

Properties

InclusiveEnd

Gets the inclusive end of the interval. (End - 1) For empty intervals, this returns Start - 1.

public long InclusiveEnd { get; }

Property Value

long

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

bool

Methods

Contains(long)

public bool Contains(long val)

Parameters

val long

Returns

bool

Equals(LongInterval)

public bool Equals(LongInterval other)

Parameters

other LongInterval

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

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

start long
inclusiveEnd long

Returns

LongInterval

Intersect(LongInterval)

Calculates the intersection between this interval and the other interval.

public LongInterval Intersect(LongInterval other)

Parameters

other LongInterval

Returns

LongInterval

Range()

Returns an enumerator over all values in this interval.

public IEnumerable<long> Range()

Returns

IEnumerable<long>

ToString()

public override string ToString()

Returns

string

Operators

operator ==(LongInterval, LongInterval)

public static bool operator ==(LongInterval lhs, LongInterval rhs)

Parameters

lhs LongInterval
rhs LongInterval

Returns

bool

operator !=(LongInterval, LongInterval)

public static bool operator !=(LongInterval lhs, LongInterval rhs)

Parameters

lhs LongInterval
rhs LongInterval

Returns

bool