-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
OrderedTable crashes on del
when there are repeated keys
#13500
Comments
I'll just repeat my comment from #12934, regarding repeated keys: I'm still of opinion that |
I am trying to get my bearings on tables before contributing to them instead of just complaining. :-) I recently posted a slight improvement to OrderedTables.del: #14971 (comment) It still is O(n) and that needs to be fixed, but it is 3x faster and uses half as much memory. And with this change, del doesn't crash on duplicate keys. I will work on a pull request for OT, my first ever on GH, so not great with it and may need some help. But it is bothering me that when OT.del() was first implemented, it did not copy the table. It did have a bug, because t.last was not updated, but it didn't make a new table. I couldn't find the commit where OT.del was changed to create a new table. Can anyone fill me in why this was done? Is it something related to immutability, del breaking iterators, or something else? I'm just wondering if copying the table is required for some reason. |
Does it? I think it just takes a |
I'm new to Nim so might not understand what I'm looking at, but it:
Also, while the test program in this PR now works, I found another one that adds 1000 duplicate keys. I modified it to delete all the keys and with the old code it segv's, but with my changes it hangs after a few are deleted. So there's still a bug in my changes I think. |
Oh yeah, sorry you are right. I was looking at the wrong proc :D |
I think the reason the table was copied is because there is potentially a backshift in Table.del(). If that occurs, the entry moves and the linked list of OT is no longer valid. That's why the test program I have is hanging. The test program adds 2 duplicate keys then a non-duplicate. The 2 dups hash to the same slot. When the dup key is deleted, the first one is deleted from slot 61 and that moves what was in slot 62 to 61. Then OT.del accesses the next key at 62, but it really is at 61. The next field is trash (0) and the program loops from 0 to 0 forever. I was planning on adding a prev field to every OT item to make a doubly-linked list so deletes would be O(1). But that won't work if nodes are moving. |
OrderedTable crashes on
del
when there are repeated keysExample
Current Output
Expected Output
Additional Information
note
see note I just added in #13418
The text was updated successfully, but these errors were encountered: