Fastest way to search a number in a list of ranges

前端 未结 5 806
终归单人心
终归单人心 2020-12-19 04:12

I have the following code to find a match for a number in a list of ranges.

public class RangeGroup
{
    public uint RangeGroupId { get; set; }
    public u         


        
5条回答
  •  有刺的猬
    2020-12-19 04:31

    If you populate the list only once you can do a magic trick:

    • Sort the List
    • Use BinarySearch

    Sort takes O(Nlog(N)) time and is only done once. Binary search takes O(log(N)), which takes at most 17 comparisons for 100.000 items.

提交回复
热议问题