Class IndexSegment
Represents a segment of indices with a beginning and ending point. Used for defining ranges of data in collections or arrays.
public class IndexSegment : IEquatable<IndexSegment>, IMakeXmlSource
- Inheritance
-
IndexSegment
- Implements
- Inherited Members
- Extension Methods
Constructors
IndexSegment()
Initializes a new instance of the IndexSegment class.
public IndexSegment()
IndexSegment(IndexSegment)
Initializes a new instance of the IndexSegment class by copying another instance.
public IndexSegment(IndexSegment src)
Parameters
src
IndexSegmentThe source index segment to copy from.
IndexSegment(int, int)
Initializes a new instance of the IndexSegment class with the specified begin and end indices.
public IndexSegment(int begin, int end)
Parameters
IndexSegment(XElement)
Initializes a new instance of the IndexSegment class from an XML element.
public IndexSegment(XElement src)
Parameters
src
XElementThe XML element containing the index segment data.
Fields
XName
The XML element name used for serialization.
public static string XName
Field Value
begin
Begin index. Inclusive.
public int begin
Field Value
end
End index. Exclusive.
public int end
Field Value
Properties
Begin
Gets or sets the beginning index of the segment (inclusive).
public int Begin { get; set; }
Property Value
End
Gets or sets the ending index of the segment (exclusive).
public int End { get; set; }
Property Value
Length
Gets the length of the segment (End - Begin).
public int Length { get; }
Property Value
Methods
Any()
Determines whether this index segment contains any indices.
public bool Any()
Returns
- bool
true if the segment contains any indices; otherwise, false.
Contains(int)
Determines whether this index segment contains the specified index.
public bool Contains(int index)
Parameters
index
intThe index to check.
Returns
- bool
true if the index is within the segment; otherwise, false.
Enumerate()
Enumerates all indices within this segment.
public IEnumerable<int> Enumerate()
Returns
- IEnumerable<int>
An enumerable collection of all indices within the segment.
Equals(IndexSegment)
Determines whether the specified index segment is equal to the current index segment.
public bool Equals(IndexSegment other)
Parameters
other
IndexSegmentThe index segment to compare with the current index segment.
Returns
- bool
true if the specified index segment is equal to the current index segment; otherwise, false.
Equals(object)
Determines whether the specified object is equal to the current index segment.
public override bool Equals(object obj)
Parameters
obj
objectThe object to compare with the current index segment.
Returns
- bool
true if the specified object is equal to the current index segment; otherwise, false.
Expand(int)
Expands this index segment to include the specified value if needed.
public void Expand(int v)
Parameters
v
intThe value to include in the segment.
GetHashCode()
Returns a hash code for this index segment.
public override int GetHashCode()
Returns
- int
A hash code for the current index segment.
GetIndexSegment<TData>(IList<TData>, int, int, Func<TData, int?>)
Gets an index segment from a list of data items based on the specified indices.
public static IndexSegment GetIndexSegment<TData>(IList<TData> steps, int cacheStepIndex, int keyStepIndex, Func<TData, int?> dataToKeyIndexFunc)
Parameters
steps
IList<TData>The list of data items.
cacheStepIndex
intThe cache step index.
keyStepIndex
intThe key step index.
dataToKeyIndexFunc
Func<TData, int?>A function that extracts an index from a data item.
Returns
- IndexSegment
An index segment representing the range of indices.
Type Parameters
TData
The type of data items.
MakeXmlSource(string, string)
Creates an XML element representing this index segment.
public XElement MakeXmlSource(string baseDirectory, string relFile)
Parameters
Returns
- XElement
An XML element representing this index segment.
ToString()
Returns a string representation of this index segment.
public override string ToString()
Returns
- string
A string representation of the current index segment.