Data structure to build and lookup set of integer ranges

前端 未结 7 1609
你的背包
你的背包 2020-12-19 09:58

I have a set of uint32 integers, there may be millions of items in the set. 50-70% of them are consecutive, but in input stream they appear in unpredictable ord

7条回答
  •  独厮守ぢ
    2020-12-19 10:26

    Keep your ranges into a sorted array and use binary search for lookups.

    It's easy to implement, O(log N), and uses less memory and needs less memory accesses than any other tree based approach, so it will probably be also much faster.

提交回复
热议问题