Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28381

Re: set and dict iteration

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'modified': 0.05; 'modify': 0.05; 'sufficient': 0.05; 'versions,': 0.05; 'python': 0.09; 'bool': 0.09; 'dict': 0.09; 'exceeds': 0.09; 'exist.': 0.09; 'longs': 0.09; 'sep': 0.09; 'subject:set': 0.09; 'unsigned': 0.09; 'worse': 0.09; 'bug': 0.10; 'cc:addr:python-list': 0.10; 'modification': 0.15; 'bugs.': 0.16; 'complicating': 0.16; 'enough.': 0.16; 'iteration': 0.16; 'iterator': 0.16; 'iterator.': 0.16; 'iterators': 0.16; 'paused': 0.16; 'rejected.': 0.16; 'set,': 0.16; 'set;': 0.16; 'skipped': 0.16; 'time).': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'unnecessary.': 0.16; 'way;': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'detect': 0.17; 'version.': 0.17; 'memory': 0.18; 'changes': 0.20; 'all,': 0.21; 'cc:2**0': 0.23; 'somebody': 0.23; 'patch': 0.24; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'propose': 0.27; 'rest': 0.28; '(my': 0.29; '-0700,': 0.29; 'argue': 0.29; "d'aprano": 0.29; 'overhead': 0.29; 'restart': 0.29; 'steven': 0.29; 'returned': 0.30; 'waste': 0.30; 'point': 0.31; 'could': 0.32; 'int': 0.33; 'point,': 0.33; 'problem': 0.33; 'another': 0.33; 'version': 0.34; 'agree': 0.34; 'minimum': 0.34; 'fail': 0.35; 'nature': 0.35; 'pm,': 0.35; "won't": 0.35; 'next': 0.35; 'created': 0.36; 'should': 0.36; 'enough': 0.36; 'keeps': 0.37; 'two': 0.37; 'why': 0.37; 'skip:4 10': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'think': 0.40; 'your': 0.60; 'first': 0.61; 'between': 0.63; 'times': 0.63; 'results': 0.65; 'risk': 0.66; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply- to:no real name:2**0': 0.72; 'counts': 0.81; '(depends': 0.84; 'common,': 0.84; 'dict,': 0.84; 'flag.': 0.84; 'overhead,': 0.84; 'received:74.208.4.194': 0.84; 'single,': 0.84; 'waste.': 0.84; 'increases': 0.91; 'realistic': 0.93; 'response,': 0.93; 'technique': 0.93
Date Mon, 03 Sep 2012 21:50:57 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: set and dict iteration
References <b8dd3aca-2a87-4124-ad6e-66a8720af99a@googlegroups.com> <mailman.3389.1345146609.4697.python-list@python.org> <7xy5le7cli.fsf@ruckus.brouhaha.com> <mailman.3404.1345158704.4697.python-list@python.org> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <fe95c29c-2289-4e9c-870e-e3c475f13459@googlegroups.com> <mailman.3435.1345240665.4697.python-list@python.org> <d4708687-2925-421a-b755-969d6dac731a@googlegroups.com> <mailman.3476.1345328046.4697.python-list@python.org> <mailman.3480.1345343315.4697.python-list@python.org> <c7452db1-5b78-4d54-81a1-1c8683631d6e@googlegroups.com> <mailman.3883.1346095064.4697.python-list@python.org> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> <mailman.154.1346700607.27098.python-list@python.org> <mailman.155.1346702665.27098.python-list@python.org> <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:C7qLVmyKdmd2Sx5+6GuW7p9sRWcGL2/GJTEh31pqgaQ AH3wS5M4HWKM6CcgDos0zxmK/KCkFYT77UIG9O9MDp9PsauBq1 MPZZ1xL0hfp8ct+CJuZJbKBJVwIjNYIZc/Vizvp6ahJJelF91I Fyb3bU2udT6FdHCdvSC+eKKsoG9Fy+Cx22KKGhU61xPdekCc58 9uEk/gRgqvkQMgp2Bev6tF1dGALYngvQbE7RvDnWkf9n7lAp6D RtmgT26Q7K2k4XCuCLxuQRlCTNpyz7FIqIUU6ax2cmw6kGBQQu xWDc2uiEoR3ko+02JM3/YXHJ32Go8s/hISJf3oW6WTffbJurw= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.162.1346723805.27098.python-list@python.org> (permalink)
Lines 61
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1346723805 news.xs4all.nl 6891 [2001:888:2000:d::a6]:60694
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28381

Show key headers only | View raw


On 09/03/2012 09:26 PM, Steven D'Aprano wrote:
> On Mon, 03 Sep 2012 13:04:23 -0700, Aaron Brady wrote:
>
>> <snip>
>>
>> I think the technique would require two python longs and a bool in the
>> set, and a python long in the iterator.
>>
>> One long counts the number of existing (open) iterators.  Another counts
>> the version.  The bool keeps track of whether an iterator has been
>> created since the last modification, in which case the next modification
>> requires incrementing the version and resetting the flag.
> I think that is over-engineered and could be the difference between 
> having the patch accepted and having it rejected. After all, many people 
> will argue that the existing solution to the problem is good enough.
>
> Dicts are extremely common, and your patch increases both the memory 
> usage of every dict, and the overhead of every write operation 
> (__setitem__, __delitem__, update). Only a very few dicts will actually 
> need this overhead, for the rest it is waste. It is important to keep 
> that waste to a minimum or risk having the patch rejected.
>
> An unsigned C int can count up to 4,294,967,295. I propose that you say 
> that is enough iterators for anyone, and use a single, simple, version 
> counter in the dict and the iterator. If somebody exceeds that many 
> iterators to a single dict or set, 

I think you have the count confused.  it has to be a count of how many
changes have been made to the dict or set, not how many iterators exist.

> and the version field overflows by 
> exactly 2**32 versions, the results are no worse than they are now. You 
> won't be introducing any new bugs.
>
> Complicating the solution is, in my opinion, unnecessary. Why should 
> every set and dict carry the cost of incrementing TWO Python longs and a 
> flag when just a single C int is sufficient for all realistic use-cases?
>
> The opportunity for failure is extremely narrow:
>
> - I must have an iterator over a dict or set;
> - and I must have paused the iteration in some way;
> - and then I must create exactly 2**32 other iterators to the 
>   same dict or set;
> - and at some point modify the dict or set
> - and then restart the first iterator
>
> at which point some items returned by the iterator *may* be duplicated or 
> skipped (depends on the nature of the modifications).
>
>

I agree with almost your entire point, exact that the place where it
would fail to detect a bug is when somebody has modified the dict
exactly 2**32 times while an iterator is paused.  See my own response,
of 4:27pm. (my time).

-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: set and dict iteration Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-27 13:17 -0600
  Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-02 10:43 -0700
    Re: set and dict iteration Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-03 13:29 -0600
      Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-03 13:04 -0700
        Re: set and dict iteration Dave Angel <d@davea.name> - 2012-09-03 16:27 -0400
          Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-03 17:24 -0700
          Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-03 17:24 -0700
      Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-03 13:04 -0700
        Re: set and dict iteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-04 01:26 +0000
          Re: set and dict iteration Dave Angel <d@davea.name> - 2012-09-03 21:50 -0400
            Re: set and dict iteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-04 01:59 +0000
              Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-08 08:42 -0700
  Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-09-02 10:43 -0700

csiph-web