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

src SortedList<TKey, V>

source

key TKey

key

searchMethod SortedListUtil.SearchMethod

search method

resultValue V

searched value

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The ending index for the search range (exclusive). Default is -1, which means the end of the list.

Returns

BinarySearchResult

search result

Type Parameters

TKey

Key type

V

Value 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

src SortedList<TKey, V>

The source sorted list.

key TKey

The key to search for.

resultListIndex int

When this method returns, contains the index of the ceiling element if found; otherwise, -1.

beginListIndex int

The starting index for the search range (inclusive).

endListIndex int

The 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

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

src SortedList<TKey, V>

The source sorted list.

key TKey

The key to search for.

resultValue V

The ceil value.

beginIndex int

The starting index for the search range (inclusive).

endIndex int

The ending index for the search range (exclusive).

Returns

BinarySearchResult

The binary search result.

Type Parameters

TKey

Key type.

V

Value 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

src SortedList<TKey, V>

source

key TKey

key

resultValue V

ceil value

ceilIndex int

The output ceil index.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The ending index for the search range (exclusive). Default is -1, which means the end of the list.

Returns

BinarySearchResult

search result

Type Parameters

TKey

Key type

V

Value 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

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.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The 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

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<TKey, V>

The source sorted list.

key TKey

The key to search for.

floorValue V

The output floor value.

floorListIndex int

The output floor list index.

startListIndex int

The start list index.

seekDirection SortedListUtil.SeekDirection

The seek direction.

Returns

BinarySearchResult

The binary search result.

Type Parameters

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<TKey, V>
key TKey
floorListIndex int
startListIndex int
seekDirection SortedListUtil.SeekDirection

Returns

BinarySearchResult

Type Parameters

TKey
V

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

src SortedList<TKey, V>

The source sorted list.

key TKey

The key to search for.

resultListIndex int

When this method returns, contains the index of the floor element if found; otherwise, -1.

beginListIndex int

The starting index for the search range (inclusive).

endListIndex int

The 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

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

src SortedList<TKey, V>

source

key TKey

key

resultValue V

floor value

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The ending index for the search range (exclusive). Default is -1, which means the end of the list.

Returns

BinarySearchResult

search result

Type Parameters

TKey

Key type

V

Value 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

src SortedList<TKey, V>

source

key TKey

key

resultValue V

floor value

floorIndex int

The output floor index.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The ending index for the search range (exclusive). Default is -1, which means the end of the list.

Returns

BinarySearchResult

search result

Type Parameters

TKey

Key type

V

Value 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

src SortedList<TKey, V>

The source sorted list.

begin TKey

The begin key.

isIncludingBeginFloor bool

Whether to include the floor of begin key.

end TKey

The end key.

isIncludingEndCeil bool

Whether to include the ceil of end key.

beginListIndex int

The starting index for the search range (inclusive).

endListIndex int

The ending index for the search range (exclusive).

Returns

Range<int>

The index range, or null if not found.

Type Parameters

TKey

The type of keys in the sorted list.

V

The 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

src SortedList<double, V>

The source sorted list.

key double

The key to search for.

resultIndex int

When this method returns, contains the index of the nearest element if found; otherwise, -1.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The 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

V

The 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

src SortedList<double, V>

The source sorted list.

key double

The key to search for.

resultKey double

When this method returns, contains the nearest key if found; otherwise, NaN.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The 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

V

The 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

src SortedList<double, V>

The source sorted list.

key double

The key to search for.

resultValue V

When this method returns, contains the value corresponding to the nearest key if found; otherwise, the default value for the type.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The 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

V

The 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

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.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The 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

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, 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

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.

beginIndex int

The starting index for the search range (inclusive). Default is 0.

endIndex int

The 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

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.