#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, Nils   |    Reviewers:  Simon King
  Bruin                              |  Work issues:
Report Upstream:  None of the above  |       Commit:
  - read trac for reasoning.         |  851cc9522dde332561101f1c84182a0a84b8eed4
         Branch:                     |     Stopgaps:
  u/SimonKing/ticket/13394           |
   Dependencies:                     |
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Replying to [comment:61 nbruin]:
 > OK, we don't have a doctest for `del_dictitem_by_exact_value`. Given
 that we absolutely want to know if somehow python changes something about
 their dicts so that our implementation needs adapting, we should include a
 stress test (perhaps `#long`?). Something along the lines of:
 > {{{
 > sage: from sage.misc.weak_dict import del_dictitem_by_exact_value
 > B=1000
 > L=list(range(B))
 > D1=dict()
 > D2=dict()
 > for i in range(100000):
 >     ki=L[floor(random()*B)]
 >     vi=L[floor(random()*B)]
 >     D1[ki]=vi
 >     D2[ki]=vi
 >     ko=L[floor(random()*B)]
 >     if ko in D1:
 >         vo=D1[ko]
 >         del D1[ko]
 >         del_dictitem_by_exact_value(D2,vo,hash(ko))
 >     assert D1 == D2
 > }}}

 I think, for an indirect doctest, one should modify it so that
 `del_dictitem_by_exact_value` is executed because a callback happens. I'll
 try to create an example accordingly. Roughly: We have two equal dicts; we
 explicitly delete an item in the first dict, and implicitly delete the
 same item in the second dict, by allowing the value to become garbage
 collected.

 For a weak value dictionary we can of course not use a list `L` of ints.
 What I don't understand: Is it essential in your example that keys and
 values come from the same list? Otherwise, I would simply have a list and
 two weak value dictionaries keeping track of the same key-value pairs, so
 that a callback is triggered if one deletes a value from the list.

--
Ticket URL: <http://trac.sagemath.org/ticket/13394#comment:71>
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.

Reply via email to