-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
removeObjectsForKeys doesn't properly remove objects #17
Comments
Can you provide the JSON and some example code the demonstrates the problem? From your description, it's not clear what the problem is. When you say "A call to removeObjectsForKeys will remove the objects but not the keys. So we end up with nil objects.", this is the expected behavior- when a |
Instead of removing the key/value pair as expected, the key remains in the mutable dictionary but the value is replaced by a null value. If I print the resulting object I can see: "myKey"=(null). |
The behavior you describe is the expected behavior. The key does not "remain" in the dictionary, any key that does not exist in the dictionary returns I suggest you try creating a |
Hey John, I think what the OP is seeing is this (with JSONKit 2e6ccf4): Code:
Output:
|
Hey John, I've tracked this down to the fix which fixed issue #8 :) Specifically this line: This comment: // If the key was in the table, we would have found it by now. Is incorrect if removeObjectForKey was used (like my example above). dictionary->entry looks like this with the example: [0] = {keyHash = 1062, key = @"a", object = "1"} So the loop terminates with NULL due to [1], but we need to keep going to find [2]. |
@omarkilani, the line you mentioned in your comment is one half of the problem. The real problem is in the removal logic- it (should have) "re-added" the items following the removed entry so that linear probe hash collisions didn't result in a Your example code was very useful- it happened to create a dictionary with 3 items with a capacity of 3 items, and I checked in a bug fix for this issue (used the new github issues feature to close this issue automagically with "Closes #17"). |
Thanks for the help reproducing the problem and fixing it. |
@johnezang, Thanks for the fix. Yeah, the real problem became obvious once I started delving in a bit more. I seem to get pretty lucky with just the right dictionaries to trigger things. :) Thanks again. |
* 'master' of github.com:playup/JSONKit: Adds a serializing option to backslash escape forward slashes. This is for issue johnezang#21. Change a NSException from exceptionWithName: to raise:. Closes johnezang#20. Fixes a bug when removing items from a JKDictionary. Since JKDictionary is implemented using a hash table that uses linear probing, the removal function needs to "re-add" items that follow the removed item so that linear probe hash collisions are not "lost". Closes johnezang#17
…ry is implemented using a hash table that uses linear probing, the removal function needs to "re-add" items that follow the removed item so that linear probe hash collisions are not "lost". Closes johnezang#17
Hi,
There is a problem with the NSMutableDictionary returned by mutableObjectFromJSONString. A call to removeObjectsForKeys will remove the objects but not the keys. So we end up with nil objects. I also noticed side effects on other dictionary values that should not be affected.
Should it be overridden in the JKDictionary class like removeObjectForKey is?
Thanks,
JF
The text was updated successfully, but these errors were encountered: