Class ListUtil
- Namespace
- Hi.Common.Collections
- Assembly
- HiGeom.dll
Provides utility methods for working with lists and collections.
public static class ListUtil
- Inheritance
-
ListUtil
- Inherited Members
Methods
GetCeilIndex<Item, ItemKey>(IList<Item>, ItemKey, Func<Item, ItemKey, int>, out int)
Gets the ceiling index of an item in a sorted list based on a key comparison.
public static BinarySearchResult GetCeilIndex<Item, ItemKey>(this IList<Item> sortedItems, ItemKey key, Func<Item, ItemKey, int> comparingFunc, out int index)
Parameters
sortedItems
IList<Item>The sorted list to search in.
key
ItemKeyThe key to search for.
comparingFunc
Func<Item, ItemKey, int>A function that compares an item to the key.
index
intWhen this method returns, contains the index of the ceiling item if found; otherwise, -1.
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search.
Type Parameters
Item
The type of items in the list.
ItemKey
The type of the key to search for.
GetCeilIndex<TKey, Item>(IList<Item>, TKey, Func<Item, TKey>, out int)
Gets the ceiling index of an item in a sorted list based on a key selector function.
public static BinarySearchResult GetCeilIndex<TKey, Item>(this IList<Item> sortedItems, TKey keyQuantity, Func<Item, TKey> getKeyQuantityFunc, out int index) where TKey : IComparable<TKey>
Parameters
sortedItems
IList<Item>The sorted list to search in.
keyQuantity
TKeyThe key to search for.
getKeyQuantityFunc
Func<Item, TKey>A function that extracts the key from an item.
index
intWhen this method returns, contains the index of the ceiling item if found; otherwise, -1.
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search.
Type Parameters
TKey
The type of the key.
Item
The type of items in the list.
GetCeil<TKey, Item>(IList<Item>, TKey, Func<Item, TKey>, out Item)
Gets the ceiling item in a sorted list based on a key selector function.
public static BinarySearchResult GetCeil<TKey, Item>(this IList<Item> sortedItems, TKey keyQuantity, Func<Item, TKey> getKeyQuantityFunc, out Item dst) where TKey : IComparable<TKey>
Parameters
sortedItems
IList<Item>The sorted list to search in.
keyQuantity
TKeyThe key to search for.
getKeyQuantityFunc
Func<Item, TKey>A function that extracts the key from an item.
dst
ItemWhen this method returns, contains the ceiling item if found; otherwise, the default value for the type.
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search.
Type Parameters
TKey
The type of the key.
Item
The type of items in the list.
GetFloorIndex<Item, ItemKey>(IList<Item>, ItemKey, Func<Item, ItemKey, int>, out int)
Gets the floor index of an item in a sorted list based on a key comparison.
public static BinarySearchResult GetFloorIndex<Item, ItemKey>(this IList<Item> sortedItems, ItemKey key, Func<Item, ItemKey, int> comparingFunc, out int index)
Parameters
sortedItems
IList<Item>The sorted list to search in.
key
ItemKeyThe key to search for.
comparingFunc
Func<Item, ItemKey, int>A function that compares an item to the key.
index
intWhen this method returns, contains the index of the floor item if found; otherwise, -1.
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search.
Type Parameters
Item
The type of items in the list.
ItemKey
The type of the key to search for.
GetFloorIndex<TKey, Item>(IList<Item>, TKey, Func<Item, TKey>, out int)
Gets the floor index of an item in a sorted list based on a key selector function.
public static BinarySearchResult GetFloorIndex<TKey, Item>(this IList<Item> sortedItems, TKey key, Func<Item, TKey> getKeyFunc, out int index) where TKey : IComparable<TKey>
Parameters
sortedItems
IList<Item>The sorted list to search in.
key
TKeyThe key to search for.
getKeyFunc
Func<Item, TKey>A function that extracts the key from an item.
index
intWhen this method returns, contains the index of the floor item if found; otherwise, -1.
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search.
Type Parameters
TKey
The type of the key.
Item
The type of items in the list.
GetFloor<TKey, Item>(IList<Item>, TKey, Func<Item, TKey>, out Item)
Gets the floor item in a sorted list based on a key selector function.
public static BinarySearchResult GetFloor<TKey, Item>(this IList<Item> sortedItems, TKey keyQuantity, Func<Item, TKey> getKeyQuantityFunc, out Item dst) where TKey : IComparable<TKey>
Parameters
sortedItems
IList<Item>The sorted list to search in.
keyQuantity
TKeyThe key to search for.
getKeyQuantityFunc
Func<Item, TKey>A function that extracts the key from an item.
dst
ItemWhen this method returns, contains the floor item if found; otherwise, the default value for the type.
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search.
Type Parameters
TKey
The type of the key.
Item
The type of items in the list.
GetIndexBasedEnumerable<TItem>(IList<TItem>)
Creates an enumerable that provides access to all elements in a list by index.
public static ListIndexBasedEnumerable<TItem> GetIndexBasedEnumerable<TItem>(this IList<TItem> src)
Parameters
src
IList<TItem>The source list
Returns
- ListIndexBasedEnumerable<TItem>
A ListIndexBasedEnumerable for the entire list
Type Parameters
TItem
The type of elements in the list
GetIndexBasedEnumerable<TItem>(IList<TItem>, int, int)
Creates an enumerable that provides access to a range of elements in a list by index.
public static ListIndexBasedEnumerable<TItem> GetIndexBasedEnumerable<TItem>(this IList<TItem> src, int begin, int end)
Parameters
src
IList<TItem>The source list
begin
intThe starting index (inclusive)
end
intThe ending index (exclusive)
Returns
- ListIndexBasedEnumerable<TItem>
A ListIndexBasedEnumerable for the specified range
Type Parameters
TItem
The type of elements in the list
GetIndexByBinarySearch<TItem>(IList<TItem>, TItem)
Performs a binary search on the specified collection.
public static int GetIndexByBinarySearch<TItem>(this IList<TItem> sortedItems, TItem value)
Parameters
sortedItems
IList<TItem>The list to be searched.
value
TItemThe value to search for.
Returns
Type Parameters
TItem
The type of the item.
GetIndexByBinarySearch<TItem>(IList<TItem>, TItem, IComparer<TItem>)
Performs a binary search on the specified collection.
public static int GetIndexByBinarySearch<TItem>(this IList<TItem> sortedItems, TItem value, IComparer<TItem> comparer)
Parameters
sortedItems
IList<TItem>The list to be searched.
value
TItemThe value to search for.
comparer
IComparer<TItem>The comparer that is used to compare the value with the list items.
Returns
Type Parameters
TItem
The type of the item.
GetIndexByBinarySearch<TItem, TSearch>(IList<TItem>, TSearch, Func<TSearch, TItem, int>)
Performs a binary search on the specified collection.
public static int GetIndexByBinarySearch<TItem, TSearch>(this IList<TItem> sortedItems, TSearch value, Func<TSearch, TItem, int> comparer)
Parameters
sortedItems
IList<TItem>The list to be searched.
value
TSearchThe value to search for.
comparer
Func<TSearch, TItem, int>The comparer that is used to compare the value with the list items.
Returns
Type Parameters
TItem
The type of the item.
TSearch
The type of the searched item.
GetInterpolatedBoundary<TItem>(List<TItem>, double, double, Func<TItem, double>, out TItem, out TItem, out TItem)
Gets interpolated boundary items from a list based on a key value and interval.
public static void GetInterpolatedBoundary<TItem>(this List<TItem> scpList, double z, double zInterval, Func<TItem, double> keyFunc, out TItem cur, out TItem floor, out TItem ceil) where TItem : IAdditionOperators<TItem, TItem, TItem>, IMultiplyOperators<TItem, double, TItem>
Parameters
scpList
List<TItem>The source list.
z
doubleThe key value to find or interpolate at.
zInterval
doubleThe interval to consider around the key value.
keyFunc
Func<TItem, double>A function that extracts the key from an item.
cur
TItemWhen this method returns, contains the interpolated item at the key value.
floor
TItemWhen this method returns, contains the floor item.
ceil
TItemWhen this method returns, contains the ceiling item.
Type Parameters
TItem
The type of items in the list, which must support addition and multiplication operators.
GetInterpolatedValue<TItem>(List<TItem>, double, Func<TItem, double>, OuterPolationMode)
Gets an interpolated value from a sorted list based on a double key, using operators for addition and multiplication.
public static TItem GetInterpolatedValue<TItem>(this List<TItem> sortedItems, double keyQuantity, Func<TItem, double> getKeyQuantityFunc, ListUtil.OuterPolationMode outerPolationMode) where TItem : IAdditionOperators<TItem, TItem, TItem>, IMultiplyOperators<TItem, double, TItem>
Parameters
sortedItems
List<TItem>The sorted list to interpolate from.
keyQuantity
doubleThe key to find or interpolate at.
getKeyQuantityFunc
Func<TItem, double>A function that extracts the key from an item.
outerPolationMode
ListUtil.OuterPolationModeThe mode to use when the key is outside the range of the list.
Returns
- TItem
The interpolated value.
Type Parameters
TItem
The type of items in the list, which must support addition and multiplication operators.
GetInterpolatedValue<TItem>(List<TItem>, double, Func<TItem, double>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>, OuterPolationMode)
Gets an interpolated value from a sorted list based on a double key.
public static TItem GetInterpolatedValue<TItem>(this List<TItem> sortedItems, double key, Func<TItem, double> getKeyFunc, Func<TItem, TItem, TItem> itemAddingFunc, Func<TItem, double, TItem> itemScalingFunc, ListUtil.OuterPolationMode outerPolationMode)
Parameters
sortedItems
List<TItem>The sorted list to interpolate from.
key
doubleThe key to find or interpolate at.
getKeyFunc
Func<TItem, double>A function that extracts the key from an item.
itemAddingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
itemScalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
outerPolationMode
ListUtil.OuterPolationModeThe mode to use when the key is outside the range of the list.
Returns
- TItem
The interpolated value.
Type Parameters
TItem
The type of items in the list.
GetInterpolatedValue<TItem>(List<TItem>, TimeSpan, Func<TItem, TimeSpan>, OuterPolationMode)
Gets an interpolated value from a sorted list based on a TimeSpan key, using operators for addition and multiplication.
public static TItem GetInterpolatedValue<TItem>(this List<TItem> sortedItems, TimeSpan keyQuantity, Func<TItem, TimeSpan> getKeyQuantityFunc, ListUtil.OuterPolationMode outerPolationMode) where TItem : IAdditionOperators<TItem, TItem, TItem>, IMultiplyOperators<TItem, double, TItem>
Parameters
sortedItems
List<TItem>The sorted list to interpolate from.
keyQuantity
TimeSpanThe TimeSpan key to find or interpolate at.
getKeyQuantityFunc
Func<TItem, TimeSpan>A function that extracts the TimeSpan key from an item.
outerPolationMode
ListUtil.OuterPolationModeThe mode to use when the key is outside the range of the list.
Returns
- TItem
The interpolated value.
Type Parameters
TItem
The type of items in the list, which must support addition and multiplication operators.
GetInterpolatedValue<TItem>(List<TItem>, TimeSpan, Func<TItem, TimeSpan>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>, OuterPolationMode)
Gets an interpolated value from a sorted list based on a TimeSpan key.
public static TItem GetInterpolatedValue<TItem>(this List<TItem> sortedItems, TimeSpan key, Func<TItem, TimeSpan> getKeyFunc, Func<TItem, TItem, TItem> itemAddingFunc, Func<TItem, double, TItem> itemScalingFunc, ListUtil.OuterPolationMode outerPolationMode)
Parameters
sortedItems
List<TItem>The sorted list to interpolate from.
key
TimeSpanThe TimeSpan key to find or interpolate at.
getKeyFunc
Func<TItem, TimeSpan>A function that extracts the TimeSpan key from an item.
itemAddingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
itemScalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
outerPolationMode
ListUtil.OuterPolationModeThe mode to use when the key is outside the range of the list.
Returns
- TItem
The interpolated value.
Type Parameters
TItem
The type of items in the list.
GetInterpolatedValue<TKey, TItem>(List<TItem>, TKey, Func<TItem, TKey>, Func<TKey, TKey, int>, Func<TKey, TKey, TKey>, Func<TKey, TKey, double>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>, OuterPolationMode)
Gets an interpolated value from a sorted list based on a key using custom comparison and arithmetic functions.
public static TItem GetInterpolatedValue<TKey, TItem>(this List<TItem> sortedItems, TKey key, Func<TItem, TKey> getKeyFunc, Func<TKey, TKey, int> keyCompareFunc, Func<TKey, TKey, TKey> keyMinusFunc, Func<TKey, TKey, double> keyDivFunc, Func<TItem, TItem, TItem> addingFunc, Func<TItem, double, TItem> scalingFunc, ListUtil.OuterPolationMode outerPolationMode)
Parameters
sortedItems
List<TItem>The sorted list of items
key
TKeyThe key to search for
getKeyFunc
Func<TItem, TKey>A function that extracts the key from an item
keyCompareFunc
Func<TKey, TKey, int>A function that compares two keys
keyMinusFunc
Func<TKey, TKey, TKey>A function that subtracts one key from another
keyDivFunc
Func<TKey, TKey, double>A function that divides one key by another
addingFunc
Func<TItem, TItem, TItem>A function that adds two items
scalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor
outerPolationMode
ListUtil.OuterPolationModeThe mode for handling values outside the range
Returns
- TItem
The interpolated value
Type Parameters
TKey
The type of the key
TItem
The type of elements in the list
GetListByKeyBoundary<TKey, TItem>(List<TItem>, Func<TItem, TKey>, TKey, bool, TKey, bool)
Gets a subset of a sorted list based on key boundaries.
public static List<TItem> GetListByKeyBoundary<TKey, TItem>(this List<TItem> sortedItems, Func<TItem, TKey> getKeyQuantityFunc, TKey begin, bool isIncludingBeginFloor, TKey end, bool isIncludingEndCeil) where TKey : IComparable<TKey>
Parameters
sortedItems
List<TItem>The sorted list to filter.
getKeyQuantityFunc
Func<TItem, TKey>A function that extracts the key from an item.
begin
TKeyThe beginning key of the range.
isIncludingBeginFloor
boolWhether to include the floor of the beginning key.
end
TKeyThe ending key of the range.
isIncludingEndCeil
boolWhether to include the ceiling of the ending key.
Returns
- List<TItem>
A new list containing only the items within the specified key range.
Type Parameters
TKey
The type of the key, which must be comparable.
TItem
The type of items in the list.
GetNearestIndex<TItem, TItemKey>(IList<TItem>, TItemKey, Func<TItem, TItemKey, double>, out int)
Finds the index of the element in a sorted list that is nearest to the specified key.
public static BinarySearchResult GetNearestIndex<TItem, TItemKey>(this IList<TItem> src, TItemKey key, Func<TItem, TItemKey, double> itemToKeyDistanceFunc, out int index)
Parameters
src
IList<TItem>The source list
key
TItemKeyThe key to search for
itemToKeyDistanceFunc
Func<TItem, TItemKey, double>A function that calculates the distance between an item and the key
index
intWhen this method returns, contains the index of the nearest element if found; otherwise, -1
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search
Type Parameters
TItem
The type of elements in the list
TItemKey
The type of the key to search for
GetNearestIndex<TItem, TItemKey>(IList<TItem>, TItemKey, Func<TItem, TItemKey, int>, Func<TItem, TItemKey, double>, out int)
Finds the index of the element in a sorted list that is nearest to the specified key using custom comparison functions.
public static BinarySearchResult GetNearestIndex<TItem, TItemKey>(this IList<TItem> src, TItemKey key, Func<TItem, TItemKey, int> itemCompareToKeyFunc, Func<TItem, TItemKey, double> itemToKeyDistanceFunc, out int index)
Parameters
src
IList<TItem>The source list (must be in ascending order)
key
TItemKeyThe key to search for
itemCompareToKeyFunc
Func<TItem, TItemKey, int>A function that compares an item to the key
itemToKeyDistanceFunc
Func<TItem, TItemKey, double>A function that calculates the distance between an item and the key
index
intWhen this method returns, contains the index of the nearest element if found; otherwise, -1
Returns
- BinarySearchResult
A BinarySearchResult indicating the result of the search
Type Parameters
TItem
The type of elements in the list
TItemKey
The type of the key to search for
Exceptions
- InvalidProgramException
Thrown when an unexpected search result occurs
GetSubListWithInterpolatedHeadAndTail<TItem>(List<TItem>, double, double, Func<TItem, double>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>)
Creates a new list with interpolated head and tail items based on the specified double key range.
public static List<TItem> GetSubListWithInterpolatedHeadAndTail<TItem>(this List<TItem> src, double beginKey, double endKey, Func<TItem, double> getKeyFunc, Func<TItem, TItem, TItem> itemAddingFunc, Func<TItem, double, TItem> itemScalingFunc)
Parameters
src
List<TItem>The source list.
beginKey
doubleThe beginning key of the range.
endKey
doubleThe ending key of the range.
getKeyFunc
Func<TItem, double>A function that extracts the double key from an item.
itemAddingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
itemScalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
Returns
- List<TItem>
A new list with interpolated head and tail items.
Type Parameters
TItem
The type of items in the list.
GetSubListWithInterpolatedHeadAndTail<TItem>(List<TItem>, TimeSpan, TimeSpan, Func<TItem, TimeSpan>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>)
Creates a new list with interpolated head and tail items based on the specified TimeSpan key range.
public static List<TItem> GetSubListWithInterpolatedHeadAndTail<TItem>(this List<TItem> src, TimeSpan beginKey, TimeSpan endKey, Func<TItem, TimeSpan> getKeyFunc, Func<TItem, TItem, TItem> itemAddingFunc, Func<TItem, double, TItem> itemScalingFunc)
Parameters
src
List<TItem>The source list.
beginKey
TimeSpanThe beginning TimeSpan key of the range.
endKey
TimeSpanThe ending TimeSpan key of the range.
getKeyFunc
Func<TItem, TimeSpan>A function that extracts the TimeSpan key from an item.
itemAddingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
itemScalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
Returns
- List<TItem>
A new list with interpolated head and tail items.
Type Parameters
TItem
The type of items in the list.
GetSubListWithInterpolatedHeadAndTail<TKey, TItem>(List<TItem>, TKey, TKey, Func<TItem, TKey>, Func<TKey, TKey, int>, Func<TKey, TKey, TKey>, Func<TKey, TKey, double>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>)
Creates a new list with interpolated head and tail items based on the specified key range.
public static List<TItem> GetSubListWithInterpolatedHeadAndTail<TKey, TItem>(this List<TItem> src, TKey beginKey, TKey endKey, Func<TItem, TKey> getKeyFunc, Func<TKey, TKey, int> keyCompareFunc, Func<TKey, TKey, TKey> keyMinusFunc, Func<TKey, TKey, double> keyDivFunc, Func<TItem, TItem, TItem> itemAddingFunc, Func<TItem, double, TItem> itemScalingFunc)
Parameters
src
List<TItem>The source list.
beginKey
TKeyThe beginning key of the range.
endKey
TKeyThe ending key of the range.
getKeyFunc
Func<TItem, TKey>A function that extracts the key from an item.
keyCompareFunc
Func<TKey, TKey, int>A function that compares two keys.
keyMinusFunc
Func<TKey, TKey, TKey>A function that subtracts one key from another.
keyDivFunc
Func<TKey, TKey, double>A function that divides one key by another to get a ratio.
itemAddingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
itemScalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
Returns
- List<TItem>
A new list with interpolated head and tail items.
Type Parameters
TKey
The type of the key.
TItem
The type of items in the list.
GetSubListWithInterpolatedTail<TItem>(List<TItem>, TimeSpan, Func<TItem, TimeSpan>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>)
Creates a new list with an interpolated tail item based on the specified TimeSpan key.
public static List<TItem> GetSubListWithInterpolatedTail<TItem>(this List<TItem> src, TimeSpan endKey, Func<TItem, TimeSpan> getKeyFunc, Func<TItem, TItem, TItem> addingFunc, Func<TItem, double, TItem> scalingFunc)
Parameters
src
List<TItem>The source list.
endKey
TimeSpanThe ending TimeSpan key for interpolation.
getKeyFunc
Func<TItem, TimeSpan>A function that extracts the TimeSpan key from an item.
addingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
scalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
Returns
- List<TItem>
A new list with an interpolated tail item.
Type Parameters
TItem
The type of items in the list.
GetSubListWithInterpolatedTail<TKey, TItem>(List<TItem>, TKey, Func<TItem, TKey>)
Creates a new list with an interpolated tail item based on the specified key, using operators for both key and item operations.
public static List<TItem> GetSubListWithInterpolatedTail<TKey, TItem>(this List<TItem> src, TKey endKey, Func<TItem, TKey> getKeyFunc) where TKey : IComparable<TKey>, ISubtractionOperators<TKey, TKey, TKey>, IDivisionOperators<TKey, TKey, double> where TItem : IAdditionOperators<TItem, TItem, TItem>, IMultiplyOperators<TItem, double, TItem>
Parameters
src
List<TItem>The source list.
endKey
TKeyThe ending key for interpolation.
getKeyFunc
Func<TItem, TKey>A function that extracts the key from an item.
Returns
- List<TItem>
A new list with an interpolated tail item.
Type Parameters
TKey
The type of the key, which must support comparison, subtraction, and division operators.
TItem
The type of items in the list, which must support addition and multiplication operators.
GetSubListWithInterpolatedTail<TKey, TItem>(List<TItem>, TKey, Func<TItem, TKey>, Func<TKey, TKey, int>, Func<TKey, TKey, TKey>, Func<TKey, TKey, double>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>)
Creates a new list with an interpolated tail item based on the specified key.
public static List<TItem> GetSubListWithInterpolatedTail<TKey, TItem>(this List<TItem> src, TKey endKey, Func<TItem, TKey> getKeyFunc, Func<TKey, TKey, int> keyCompareFunc, Func<TKey, TKey, TKey> keyMinusFunc, Func<TKey, TKey, double> keyDivFunc, Func<TItem, TItem, TItem> itemAddingFunc, Func<TItem, double, TItem> itemScalingFunc)
Parameters
src
List<TItem>The source list.
endKey
TKeyThe ending key for interpolation.
getKeyFunc
Func<TItem, TKey>A function that extracts the key from an item.
keyCompareFunc
Func<TKey, TKey, int>A function that compares two keys.
keyMinusFunc
Func<TKey, TKey, TKey>A function that subtracts one key from another.
keyDivFunc
Func<TKey, TKey, double>A function that divides one key by another to get a ratio.
itemAddingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
itemScalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
Returns
- List<TItem>
A new list with an interpolated tail item.
Type Parameters
TKey
The type of the key.
TItem
The type of items in the list.
GetSubListWithInterpolatedTail<TKey, TItem>(List<TItem>, TKey, Func<TItem, TKey>, Func<TItem, TItem, TItem>, Func<TItem, double, TItem>)
Creates a new list with an interpolated tail item based on the specified key, using operators for key operations.
public static List<TItem> GetSubListWithInterpolatedTail<TKey, TItem>(this List<TItem> src, TKey endKey, Func<TItem, TKey> getKeyFunc, Func<TItem, TItem, TItem> addingFunc, Func<TItem, double, TItem> scalingFunc) where TKey : IComparable<TKey>, ISubtractionOperators<TKey, TKey, TKey>, IDivisionOperators<TKey, TKey, double>
Parameters
src
List<TItem>The source list.
endKey
TKeyThe ending key for interpolation.
getKeyFunc
Func<TItem, TKey>A function that extracts the key from an item.
addingFunc
Func<TItem, TItem, TItem>A function that adds two items together.
scalingFunc
Func<TItem, double, TItem>A function that scales an item by a factor.
Returns
- List<TItem>
A new list with an interpolated tail item.
Type Parameters
TKey
The type of the key, which must support comparison, subtraction, and division operators.
TItem
The type of items in the list.
Swap<TItem>(IList<TItem>, int, int)
Swaps two elements in a list at the specified indices.
public static void Swap<TItem>(this IList<TItem> src, int indexA, int indexB)
Parameters
src
IList<TItem>The source list
indexA
intThe index of the first element to swap
indexB
intThe index of the second element to swap
Type Parameters
TItem
The type of elements in the list
TestFloorCeil()
Tests the floor and ceiling functionality with sample data.
public static void TestFloorCeil()