Searches a sorted list for a key via binary search. The list must be sorted by the ordering in the passed comparison.
public static int BinarySearchForKey<TItem, TKey>(IReadOnlyList<TItem> list, TKey key,
Func<TItem, TKey, int> compare, out int index)
parameter | description |
---|---|
list | The sorted list to search. |
key | The key to search for. |
compare | The comparison. |
index | Returns the first index at which the key can be found. If the return value is zero, indicating that key was not present in the list, then this returns the index at which key could be inserted to maintain the sorted order of the list. |
The number of keys equal to key that appear in the list.
Modified from similar function in PowerCollections, copyright (c) 2004-2005, Wintellect.