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, SearchMethod, out V, int, int)
Get value by searchMethod.
If return value is NotExisted, resultValue will be the default value of V.
public static BinarySearchResult GetByMethod<TKey, V>(this SortedList<TKey, V> src, TKey key, SortedListUtil.SearchMethod searchMethod, out V resultValue, int beginIndex = 0, int endIndex = -1) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
searchMethodSortedListUtil.SearchMethodsearch 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
- BinarySearchResult
search result
Type Parameters
TKeyKey type
VValue type
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult GetFloorBySeek<TKey, V>(this SortedList<TKey, V> src, TKey key, out V floorValue, out int floorListIndex, int startListIndex, SortedListUtil.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.
startListIndexintThe start list index.
seekDirectionSortedListUtil.SeekDirectionThe seek direction.
Returns
- BinarySearchResult
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)
public static BinarySearchResult GetFloorListIndexBySeek<TKey, V>(this SortedList<TKey, V> src, TKey key, out int floorListIndex, int startListIndex, SortedListUtil.SeekDirection seekDirection = SeekDirection.Free) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>keyTKeyfloorListIndexintstartListIndexintseekDirectionSortedListUtil.SeekDirection
Returns
Type Parameters
TKeyV
Remarks
The Free seek direction does not loss additional performance.
The seek direction only effect the resulting value by the startListIndex 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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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 BinarySearchResult 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
- BinarySearchResult
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.