A dictionary object that uses ranges of values for keys

前端 未结 8 849
情深已故
情深已故 2020-11-27 19:26

I have need of a sort of specialized dictionary. My use case is this: The user wants to specify ranges of values (the range could be a single point as well) and assign a v

8条回答
  •  甜味超标
    2020-11-27 19:58

    I have solved a similar problem by ensuring that the collection is contiguous where the intervals never overlap and never have gaps between them. Each interval is defined as a lower boundary and any value lies in that interval if it is equal to or greater than that boundary and less than the lower boundary of the next interval. Anything below the lowest boundary is a special case bin.

    This simplifies the problem somewhat. We also then optimized key searches by implementing a binary chop. I can't share the code, unfortunately.

提交回复
热议问题