Table of Contents

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

src SortedList<TKey, V>

source

key TKey

key

searchMethod SortedListUtil.SearchMethod

search method

result BinarySearchResult

result

Returns

V

searched value

Type Parameters

TKey

Key type

V

Value 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

src SortedList<TKey, V>

The source sorted list.

key TKey

The key to search for.

result BinarySearchResult

When 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

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<TKey, V>

source

key TKey

key

result BinarySearchResult

result

Returns

V

ceil value

Type Parameters

TKey

Key type

V

Value 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

src SortedList<TKey, V>

The source sorted list.

begin TKey

The beginning key of the range.

isIncludingBeginFloor bool

Whether to include the floor value of the beginning key.

end TKey

The ending key of the range.

isIncludingEndCeil bool

Whether 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

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<TKey, V>

The source sorted list.

key TKey

The key to search for.

result BinarySearchResult

When 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

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<TKey, V>

source

key TKey

key

result BinarySearchResult

result

Returns

V

floor value

Type Parameters

TKey

Key type

V

Value 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

src SortedList<double, V>

The source sorted list.

key double

The key to search for.

result BinarySearchResult

When 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

V

The 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

src SortedList<double, V>

The source sorted list.

key double

The key to search for.

result BinarySearchResult

When 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

V

The 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

src SortedList<double, V>

The source sorted list.

key double

The key to search for.

result BinarySearchResult

When 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

V

The 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

src SortedList<TKey, V>

The source sorted list.

begin TKey

The beginning key of the range.

isIncludingBeginFloor bool

Whether to include the floor value of the beginning key.

end TKey

The ending key of the range.

isIncludingEndCeil bool

Whether 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

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<TKey, V>

The source sorted list.

begin TKey

The beginning key of the range.

isIncludingBeginFloor bool

Whether to include the floor value of the beginning key.

end TKey

The ending key of the range.

isIncludingEndCeil bool

Whether to include the ceiling value of the ending key.

Returns

List<V>

A list of values within the specified range.

Type Parameters

TKey

The type of keys in the sorted list.

V

The 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

src List<TValue>

The source list of values.

keyFunc Func<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

TKey

The type of keys in the resulting sorted list.

TValue

The type of values in the list and the resulting sorted list.