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 BinarySearchResult)
Get value by searchMethod.
If result is NotExisted, return the default value of V.
public static V GetByMethod<TKey, V>(this SortedList<TKey, V> src, TKey key, SortedListUtil.SearchMethod searchMethod, out BinarySearchResult result) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
searchMethodSortedListUtil.SearchMethodsearch method
resultBinarySearchResultresult
Returns
- V
searched value
Type Parameters
TKeyKey type
VValue type
GetCeilIndex<TKey, V>(SortedList<TKey, V>, TKey, out BinarySearchResult)
Gets the index of the element in a sorted list that has a key greater than or equal to a specified key.
public static int GetCeilIndex<TKey, V>(this SortedList<TKey, V> src, TKey key, out BinarySearchResult result) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
resultBinarySearchResultWhen this method returns, contains a value indicating whether an exact match was found, a ceiling value was found, or no suitable element exists.
Returns
- int
The index of the ceiling element if found; otherwise, -1.
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 BinarySearchResult)
Get ceil value by key.
If result is NotExisted, return the default value of V.
public static V GetCeil<TKey, V>(this SortedList<TKey, V> src, TKey key, out BinarySearchResult result) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
resultBinarySearchResultresult
Returns
- V
ceil value
Type Parameters
TKeyKey type
VValue type
GetEnumerableByKeyBoundary<TKey, V>(SortedList<TKey, V>, TKey, bool, TKey, bool)
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) 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.
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.
GetFloorIndex<TKey, V>(SortedList<TKey, V>, TKey, out BinarySearchResult)
Gets the index of the element in a sorted list that has a key less than or equal to a specified key.
public static int GetFloorIndex<TKey, V>(this SortedList<TKey, V> src, TKey key, out BinarySearchResult result) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>The source sorted list.
keyTKeyThe key to search for.
resultBinarySearchResultWhen this method returns, contains a value indicating whether an exact match was found, a floor value was found, or no suitable element exists.
Returns
- int
The index of the floor element if found; otherwise, -1.
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 BinarySearchResult)
Get floor value by key.
If result is NotExisted, return the default value of V.
public static V GetFloor<TKey, V>(this SortedList<TKey, V> src, TKey key, out BinarySearchResult result) where TKey : IComparable<TKey>
Parameters
srcSortedList<TKey, V>source
keyTKeykey
resultBinarySearchResultresult
Returns
- V
floor value
Type Parameters
TKeyKey type
VValue type
GetNearestIndex<V>(SortedList<double, V>, double, out BinarySearchResult)
Gets the index of the element in a sorted list that has a key nearest to a specified key.
public static int GetNearestIndex<V>(this SortedList<double, V> src, double key, out BinarySearchResult result)
Parameters
srcSortedList<double, V>The source sorted list.
keydoubleThe key to search for.
resultBinarySearchResultWhen this method returns, contains a value indicating whether an exact match was found, or the nearest floor/ceiling value.
Returns
- int
The index of the nearest element if found; otherwise, -1.
Type Parameters
VThe type of values in the sorted list.
GetNearestKey<V>(SortedList<double, V>, double, out BinarySearchResult)
Gets the key in a sorted list that is nearest to a specified key.
public static double GetNearestKey<V>(this SortedList<double, V> src, double key, out BinarySearchResult result)
Parameters
srcSortedList<double, V>The source sorted list.
keydoubleThe key to search for.
resultBinarySearchResultWhen this method returns, contains a value indicating whether an exact match was found, or the nearest floor/ceiling value.
Returns
- double
The nearest key if found; otherwise, NaN.
Type Parameters
VThe type of values in the sorted list.
GetNearestValue<V>(SortedList<double, V>, double, out BinarySearchResult)
Gets the value in a sorted list that corresponds to the key nearest to a specified key.
public static V GetNearestValue<V>(this SortedList<double, V> src, double key, out BinarySearchResult result)
Parameters
srcSortedList<double, V>The source sorted list.
keydoubleThe key to search for.
resultBinarySearchResultWhen this method returns, contains a value indicating whether an exact match was found, or the nearest floor/ceiling value.
Returns
- V
The value corresponding to the nearest key if found; otherwise, the default value for the type.
Type Parameters
VThe type of values in the sorted list.
GetSortedListByKeyBoundary<TKey, V>(SortedList<TKey, V>, TKey, bool, TKey, bool)
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) 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.
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)
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) 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.
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.