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
TKeyThe comparable endpoint type.
TValueThe 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
startInclusiveTKeyThe inclusive start of the range.
endExclusiveTKeyThe exclusive end of the range.
valueTValueThe value mapped to the range.
Exceptions
- ArgumentNullException
startInclusiveorendExclusiveis null.- ArgumentException
startInclusiveis greater than or equal toendExclusive.
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
keyTKeyThe key to test. Must not be null.
Returns
Exceptions
- ArgumentNullException
keyis null.
Equals(ValueRange<TKey, TValue>)
Determines whether two entries have identical endpoints and equal values.
public bool Equals(ValueRange<TKey, TValue> other)
Parameters
otherValueRange<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
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
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
leftValueRange<TKey, TValue>The left operand.
rightValueRange<TKey, TValue>The right operand.
Returns
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
leftValueRange<TKey, TValue>The left operand.
rightValueRange<TKey, TValue>The right operand.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |