Cysharp / MasterMemory

Embedded Typed Readonly In-Memory Document Database for .NET and Unity.
MIT License
1.52k stars 110 forks source link

Fix for FindManyRangeCore returns invalid range Issue 57 #58

Closed tfindlow closed 4 years ago

tfindlow commented 4 years ago

Hi,

This open source thing is new to me. My apologies in advance if I'm not following the expected protocol.

I created issue number 57 on the main repo - outlining an issue I had with RangeView.FindManyRangeCore returning an invalid range when the data is entirely outside the range given by min and max parameters.

This pull request includes a proposed solution. The solution does change the values from BinarySearch.FindClosest, the values outside the range [1, N] are now being checked outside the BinarySearch routine (see TableBase.FindManyClosestCore). The definition of Empty also changed to take -1, -1 as the default zero left/right values resulted in a FirstIndex/LastIndex that pointed to a valid entry in the index array.

To reduce the number of binary search calls by FindManyRangeCore, I added two new routines to BinarySearch: LowerBoundClosest and UpperBoundClosest.

I have also added some additional tests that cover the case.

Hope you can use the work. I like this project very much.

Regards Tim

neuecc commented 4 years ago

Thanks for the great fix, and sorry for the delayed response. We will take your suggestions and merge them.