-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
search algorithm doesn't take duplicate keys into account #16
Comments
@Mamonaku Thanks for reporting. I'm not sure I agree that this should be considered a bug. Can you provide the code of an actual algorithm that fails but shouldn't? |
Hello @ole ,
output is
The problem is that if I want to enumerate multiple keys (which should be possible because a Sorted Array does store multiple keys, so access ought to be implemented), they I can't find them anymore. hope this helps. |
@Mamonaku Thanks for the example. Sorry, I still don't understand what you're trying to do.
What do you mean by this? What's the concrete problem you're trying to solve? As far as I can tell, the example you posted above doesn't represent an algorithm that fails because of As a side note, the /// If the array contains multiple elements that are equal to `newElement`,
/// there is no guarantee which of these is found. (I'm not saying the functionality you're looking for is wrong or that it shouldn't exist. I'm just trying to understand.) |
@ole , I was looking for a storage solution, where objects are keyed by categories, so that multiple objects of the same category could be enumerated, through a sequence protocol conformance. I think it would be a good addition to your code, but that's just me. I went for a BTree eventually, with duplicate key support, but I found it overkill (although works fine). |
Thanks, now it makes sense to me. |
Thanks! |
Hello,
I think the algorithm :
Doesn't take into account the case where duplicate keys are present. In particular, in calculating the mid point, it'll give the index value of the first occurence of newElement == candidate, not the smallest index.
As a result, enumerating all keys verifying k == 0 (for example), will fail. One has to find the lowest value for which areInIncreasingOrder(candidate, newElement) == true and areInIncreasingOrder(newElement, candidate + 1) == false.
If I find a quick solution, I'll let you know.
The text was updated successfully, but these errors were encountered: