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: 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 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 Subject: Re: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 09/03/2012 09:26 PM, Steven D'Aprano wrote: > On Mon, 03 Sep 2012 13:04:23 -0700, Aaron Brady wrote: > >> >> >> 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