Class SortedListUtil
- Namespace
- Hi.Common.Collections
- Assembly
- HiGeom.dll
Utility class providing extension methods for SortedList operations.
public static class SortedListUtil
- Inheritance
-
SortedListUtil
- Inherited Members
Methods
GetByMethod<TKey, V>(SortedList<TKey, V>, TKey, SearchTargetMode, out V, int, int)
Get value by searchMethod.
If return value is NotExisted, resultValue will be the default value of V.
public static SearchResult GetByMethod<TKey, V>(this SortedList<TKey, V> src, TKey key, SearchTargetMode searchMethod, out V resultValue, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
searchMethodSearchTargetModesearch method
resultValueVsearched value
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
search result
Type Parameters
TKeyKey type
VValue type
GetCeilBySeek<TKey, V>(SortedList<TKey, V>, TKey, out V, out int, int, SeekDirection)
Gets the ceil value by seeking with the specified direction.
public static SearchResult GetCeilBySeek<TKey, V>(this SortedList<TKey, V> src, TKey key, out V ceilValue, out int ceilListIndex, int seekingStartListIndex, SeekDirection seekDirection = SeekDirection.Free) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
ceilValueVThe output ceil value.
ceilListIndexintThe output ceil list index.
seekingStartListIndexintThe start list index for seeking.
seekDirectionSeekDirectionThe seek direction.
Returns
- SearchResult
The binary search result.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetCeilListIndexBySeek<TKey, V>(SortedList<TKey, V>, TKey, out int, int, SeekDirection)
Gets the ceil list index by seeking with the specified direction.
public static SearchResult GetCeilListIndexBySeek<TKey, V>(this SortedList<TKey, V> src, TKey key, out int ceilListIndex, int seekingStartListIndex, SeekDirection seekDirection = SeekDirection.Free) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
ceilListIndexintThe output ceil list index.
seekingStartListIndexintStart list index for seeking.
seekDirectionSeekDirectionThe seek direction. Default is Free.
Returns
- SearchResult
The search result.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
Remarks
The Free seek direction does not loss additional performance.
The seek direction only effect the resulting value by the seekingStartListIndex bound.
GetCeilListIndex<TKey, V>(SortedList<TKey, V>, TKey, out int, int, int)
Gets the index of the element in a sorted list that has a key greater than or equal to a specified key.
public static SearchResult GetCeilListIndex<TKey, V>(this SortedList<TKey, V> src, TKey key, out int resultListIndex, int beginListIndex = 0, int endListIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
resultListIndexintWhen this method returns, contains the index of the ceiling element if found; otherwise, -1.
beginListIndexintThe starting index for the search range (inclusive).
endListIndexintThe ending index for the search range (exclusive).
Returns
- SearchResult
A value indicating whether an exact match was found, a ceiling value was found, or no suitable element exists.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetCeil<TKey, V>(SortedList<TKey, V>, TKey, out V, int, int)
Get ceil value by key without returning the ceil index.
public static SearchResult GetCeil<TKey, V>(this SortedList<TKey, V> src, TKey key, out V resultValue, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
resultValueVThe ceil value.
beginIndexintThe starting index for the search range (inclusive).
endIndexintThe ending index for the search range (exclusive).
Returns
- SearchResult
The binary search result.
Type Parameters
TKeyKey type.
VValue type.
GetCeil<TKey, V>(SortedList<TKey, V>, TKey, out V, out int, int, int)
Get ceil value by key.
If return value is NotExisted, resultValue will be the default value of V.
public static SearchResult GetCeil<TKey, V>(this SortedList<TKey, V> src, TKey key, out V resultValue, out int ceilIndex, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
resultValueVceil value
ceilIndexintThe output ceil index.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
search result
Type Parameters
TKeyKey type
VValue type
GetEnumerableByKeyBoundary<TKey, V>(SortedList<TKey, V>, TKey, bool, TKey, bool, int, int)
Gets a sequence of key-value pairs from a sorted list within a specified key range.
public static IEnumerable<KeyValuePair<TKey, V>> GetEnumerableByKeyBoundary<TKey, V>(this SortedList<TKey, V> src, TKey begin, bool isIncludingBeginFloor, TKey end, bool isIncludingEndCeil, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
beginTKeyThe beginning key of the range.
isIncludingBeginFloorboolWhether to include the floor value of the beginning key.
endTKeyThe ending key of the range.
isIncludingEndCeilboolWhether to include the ceiling value of the ending key.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- IEnumerable<KeyValuePair<TKey, V>>
A sequence of key-value pairs within the specified range.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetFloorBySeek<TKey, V>(SortedList<TKey, V>, TKey, out V, out int, int, SeekDirection)
Gets the floor value by seeking with the specified direction.
public static SearchResult GetFloorBySeek<TKey, V>(this SortedList<TKey, V> src, TKey key, out V floorValue, out int floorListIndex, int seekingStartListIndex, SeekDirection seekDirection = SeekDirection.Free) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
floorValueVThe output floor value.
floorListIndexintThe output floor list index.
seekingStartListIndexintThe start list index for seeking.
seekDirectionSeekDirectionThe seek direction.
Returns
- SearchResult
The binary search result.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetFloorListIndexBySeek<TKey, V>(SortedList<TKey, V>, TKey, out int, int, SeekDirection)
Gets the floor list index by seeking with the specified direction.
public static SearchResult GetFloorListIndexBySeek<TKey, V>(this SortedList<TKey, V> src, TKey key, out int floorListIndex, int seekingStartListIndex, SeekDirection seekDirection = SeekDirection.Free) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
floorListIndexintThe output floor list index.
seekingStartListIndexintStart list index for seeking.
seekDirectionSeekDirectionThe seek direction. Default is Free.
Returns
- SearchResult
The search result.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
Remarks
The Free seek direction does not loss additional performance.
The seek direction only effect the resulting value by the seekingStartListIndex bound.
GetFloorListIndex<TKey, V>(SortedList<TKey, V>, TKey, out int, int, int)
Gets the index of the element in a sorted list that has a key less than or equal to a specified key.
public static SearchResult GetFloorListIndex<TKey, V>(this SortedList<TKey, V> src, TKey key, out int resultListIndex, int beginListIndex = 0, int endListIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
resultListIndexintWhen this method returns, contains the index of the floor element if found; otherwise, -1.
beginListIndexintThe starting index for the search range (inclusive).
endListIndexintThe ending index for the search range (exclusive).
Returns
- SearchResult
A value indicating whether an exact match was found, a floor value was found, or no suitable element exists.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetFloor<TKey, V>(SortedList<TKey, V>, TKey, out V, int, int)
Get floor value by key.
If return value is NotExisted, resultValue will be the default value of V.
public static SearchResult GetFloor<TKey, V>(this SortedList<TKey, V> src, TKey key, out V resultValue, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
resultValueVfloor value
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
search result
Type Parameters
TKeyKey type
VValue type
GetFloor<TKey, V>(SortedList<TKey, V>, TKey, out V, out int, int, int)
Get floor value by key.
If return value is NotExisted, resultValue will be the default value of V.
public static SearchResult GetFloor<TKey, V>(this SortedList<TKey, V> src, TKey key, out V resultValue, out int floorIndex, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
resultValueVfloor value
floorIndexintThe output floor index.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
search result
Type Parameters
TKeyKey type
VValue type
GetIndexRangeByKeyBoundary<TKey, V>(SortedList<TKey, V>, TKey, bool, TKey, bool, int, int)
Gets the index range by key boundary.
public static Range<int> GetIndexRangeByKeyBoundary<TKey, V>(this SortedList<TKey, V> src, TKey begin, bool isIncludingBeginFloor, TKey end, bool isIncludingEndCeil, int beginListIndex = 0, int endListIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
beginTKeyThe begin key.
isIncludingBeginFloorboolWhether to include the floor of begin key.
endTKeyThe end key.
isIncludingEndCeilboolWhether to include the ceil of end key.
beginListIndexintThe starting index for the search range (inclusive).
endListIndexintThe ending index for the search range (exclusive).
Returns
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetNearestIndex<V>(SortedList<double, V>, double, out int, int, int)
Gets the index of the element in a sorted list that has a key nearest to a specified key.
public static SearchResult GetNearestIndex<V>(this SortedList<double, V> src, double key, out int resultIndex, int beginIndex = 0, int endIndex = -1)
Parameters
srcSortedList<double, V>The source sorted list.
keydoubleThe key to search for.
resultIndexintWhen this method returns, contains the index of the nearest element if found; otherwise, -1.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
A value indicating whether an exact match was found, or the nearest floor/ceiling value.
Type Parameters
VThe type of values in the sorted list.
GetNearestKey<V>(SortedList<double, V>, double, out double, int, int)
Gets the key in a sorted list that is nearest to a specified key.
public static SearchResult GetNearestKey<V>(this SortedList<double, V> src, double key, out double resultKey, int beginIndex = 0, int endIndex = -1)
Parameters
srcSortedList<double, V>The source sorted list.
keydoubleThe key to search for.
resultKeydoubleWhen this method returns, contains the nearest key if found; otherwise, NaN.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
A value indicating whether an exact match was found, or the nearest floor/ceiling value.
Type Parameters
VThe type of values in the sorted list.
GetNearestValue<V>(SortedList<double, V>, double, out V, int, int)
Gets the value in a sorted list that corresponds to the key nearest to a specified key.
public static SearchResult GetNearestValue<V>(this SortedList<double, V> src, double key, out V resultValue, int beginIndex = 0, int endIndex = -1)
Parameters
srcSortedList<double, V>The source sorted list.
keydoubleThe key to search for.
resultValueVWhen this method returns, contains the value corresponding to the nearest key if found; otherwise, the default value for the type.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SearchResult
A value indicating whether an exact match was found, or the nearest floor/ceiling value.
Type Parameters
VThe type of values in the sorted list.
GetSortedListByKeyBoundary<TKey, V>(SortedList<TKey, V>, TKey, bool, TKey, bool, int, int)
Creates a new sorted list containing key-value pairs from a source sorted list within a specified key range.
public static SortedList<TKey, V> GetSortedListByKeyBoundary<TKey, V>(this SortedList<TKey, V> src, TKey begin, bool isIncludingBeginFloor, TKey end, bool isIncludingEndCeil, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
beginTKeyThe beginning key of the range.
isIncludingBeginFloorboolWhether to include the floor value of the beginning key.
endTKeyThe ending key of the range.
isIncludingEndCeilboolWhether to include the ceiling value of the ending key.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- SortedList<TKey, V>
A new sorted list containing key-value pairs within the specified range.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
GetValuesByKeyBoundary<TKey, V>(SortedList<TKey, V>, TKey, bool, TKey, bool, int, int)
Gets a list of values from a sorted list within a specified key range.
public static List<V> GetValuesByKeyBoundary<TKey, V>(this SortedList<TKey, V> src, TKey begin, bool isIncludingBeginFloor, TKey end, bool isIncludingEndCeil, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
beginTKeyThe beginning key of the range.
isIncludingBeginFloorboolWhether to include the floor value of the beginning key.
endTKeyThe ending key of the range.
isIncludingEndCeilboolWhether to include the ceiling value of the ending key.
beginIndexintThe starting index for the search range (inclusive). Default is 0.
endIndexintThe ending index for the search range (exclusive). Default is -1, which means the end of the list.
Returns
- List<V>
A list of values within the specified range.
Type Parameters
TKeyThe type of keys in the sorted list.
VThe type of values in the sorted list.
ToSortedList<TKey, TValue>(List<TValue>, Func<TValue, TKey>)
Converts a list of values to a sorted list using a key selector function.
public static SortedList<TKey, TValue> ToSortedList<TKey, TValue>(this List<TValue> src, Func<TValue, TKey> keyFunc) where TKey : IComparable<TKey>
Parameters
srcList<TValue>The source list of values.
keyFuncFunc<TValue, TKey>A function to extract a key from each value.
Returns
- SortedList<TKey, TValue>
A sorted list containing the values from the source list, keyed by the extracted keys.
Type Parameters
TKeyThe type of keys in the resulting sorted list.
TValueThe type of values in the list and the resulting sorted list.