Table of Contents

ValueRange<TKey, TValue> Struct

Definition

Namespace
Bodu.Collections.Generic
Assembly
Bodu.Collections.dll
Package
Bodu.Collections 1.0.0
Source
ValueRange{T,T}.cs

Represents a half-open range mapped to a value - the entry projection produced when enumerating a RangeDictionary<TKey, TValue>.

public readonly struct ValueRange<TKey, TValue> : IEquatable<ValueRange<TKey, TValue>> where TKey : IComparable<TKey>

Type Parameters

TKey

The comparable endpoint type.

TValue

The value type associated with the range.

Implements
IEquatable<ValueRange<TKey, TValue>>
Inherited Members
Extension Methods

Remarks

ValueRange<TKey, TValue> pairs a half-open range - [StartInclusive, EndExclusive) - with an associated value, in the spirit of KeyValuePair<TKey, TValue> for keyed dictionaries. It is the element type returned by RangeDictionary<TKey, TValue> enumeration and the natural shape for any API that projects keyed ranges.

The public constructor validates that the start endpoint is strictly less than the end endpoint under Default and rejects degenerate or inverted ranges with ArgumentException. Owning collections that have already validated endpoints during insertion may use an internal unchecked overload to avoid re-validating during projection.

Constructors

ValueRange(TKey, TKey, TValue)

Initializes a new instance of the ValueRange<TKey, TValue> struct.

public ValueRange(TKey startInclusive, TKey endExclusive, TValue value)

Parameters

startInclusive TKey

The inclusive start of the range.

endExclusive TKey

The exclusive end of the range.

value TValue

The value mapped to the range.

Exceptions

ArgumentNullException

startInclusive or endExclusive is null.

ArgumentException

startInclusive is greater than or equal to endExclusive.

Properties

EndExclusive

Gets the exclusive end of the range.

public TKey EndExclusive { get; }

Property Value

TKey

The exclusive upper bound of the range.

StartInclusive

Gets the inclusive start of the range.

public TKey StartInclusive { get; }

Property Value

TKey

The inclusive lower bound of the range.

Value

Gets the value associated with the range.

public TValue Value { get; }

Property Value

TValue

The value mapped to this range.

Methods

Contains(TKey)

Determines whether the specified key falls inside this range.

public bool Contains(TKey key)

Parameters

key TKey

The key to test. Must not be null.

Returns

bool

true if key is inside the range; otherwise, false.

Exceptions

ArgumentNullException

key is null.

Equals(ValueRange<TKey, TValue>)

Determines whether two entries have identical endpoints and equal values.

public bool Equals(ValueRange<TKey, TValue> other)

Parameters

other ValueRange<TKey, TValue>

The entry to compare with this instance.

Returns

bool

true if the entries share the same start and end and their values compare equal; otherwise, false.

Remarks

Endpoints are compared with Default and values with Default.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(ValueRange<TKey, TValue>, ValueRange<TKey, TValue>)

Returns a value indicating whether two entries have identical endpoints and equal values.

public static bool operator ==(ValueRange<TKey, TValue> left, ValueRange<TKey, TValue> right)

Parameters

left ValueRange<TKey, TValue>

The left operand.

right ValueRange<TKey, TValue>

The right operand.

Returns

bool

true if the operands are equal; otherwise, false.

operator !=(ValueRange<TKey, TValue>, ValueRange<TKey, TValue>)

Returns a value indicating whether two entries differ in endpoints or value.

public static bool operator !=(ValueRange<TKey, TValue> left, ValueRange<TKey, TValue> right)

Parameters

left ValueRange<TKey, TValue>

The left operand.

right ValueRange<TKey, TValue>

The right operand.

Returns

bool

true if the operands are not equal; otherwise, false.

Applies to

ProductVersions
.NET8, 10