#13394: Write a WeakValueDictionary with safer key removal
-------------------------------------+-------------------------------------
Reporter: nbruin | Owner: rlm
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.13
Component: memleak | Resolution:
Keywords: | Merged in:
Authors: Simon King | Reviewers:
Report Upstream: None of the above | Work issues:
- read trac for reasoning. | Commit:
Branch: | fab0ed4112b9f798e2690f4c885b57cd711ea698
u/SimonKing/ticket/13394 | Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by nbruin):
Replying to [comment:46 SimonKing]:
> But then I wonder: How does a straight Python dict prevents this from
happening? I.e., if a hash bucket `B` is searched for equality with a key
`K`, how does Python make sure that the comparison with `K` does not
change the length of `B`?
It doesn't (and also bucket lengths are irrelevant for Python dicts). It
only has one contract: Entries in the dictionary ONLY change location when
the allocated space of the dictionary is resized. And resizing ONLY
happens when a (key,value) pair gets added to the dictionary that wasn't
previously there. If the value of an already existing key gets updated,
the dictionary is guaranteed to not be resized either.
That said, yes, when probing the dictionary, it's checked every iteration
if the dictionary has been resized:
[http://hg.python.org/cpython/file/a28f3eebe8ae/Objects/dictobject.c#l491
dictobject.c line 1491]. This bit used to have a warning that a devious
advisary could make this not finish.
I need to look at your other example ...
--
Ticket URL: <http://trac.sagemath.org/ticket/13394#comment:49>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.