Re: set and dict iteration

2012-09-10 Thread 88888 Dihedral
Paul Rubin於 2012年8月17日星期五UTC+8上午9時01分39秒寫道: > Ian Kelly writes: > > > With regard to key insertion and deletion while iterating over a dict > > > or set, though, there is just no good reason to be doing that > > > (especially as the result is very implementation-specific), and I > > > wouldn't

Re: set and dict iteration

2012-09-08 Thread Aaron Brady
On Thursday, August 23, 2012 1:11:14 PM UTC-5, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 09:49:41 -0700, Aaron Brady wrote: > > > > [...] > > > The patch for the above is only 40-60 lines. However it introduces two > > > new concepts. > > > > > > The first is a "linked list", a classic

Re: set and dict iteration

2012-09-08 Thread MRAB
On 08/09/2012 21:06, Thomas Rachel wrote: Am 19.08.2012 00:14 schrieb MRAB: Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? In simple terms, when you create an immutable object it can contain only references to pre-existing objects

Re: set and dict iteration

2012-09-08 Thread Hans Mulder
On 8/09/12 22:06:08, Thomas Rachel wrote: > Am 19.08.2012 00:14 schrieb MRAB: > >>> Can someone who is more familiar with the cycle detector and cycle >>> breaker, help prove or disprove the above? >>> >> In simple terms, when you create an immutable object it can contain >> only references to pre

Re: set and dict iteration

2012-09-08 Thread Thomas Rachel
Am 19.08.2012 00:14 schrieb MRAB: Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? In simple terms, when you create an immutable object it can contain only references to pre-existing objects, but in order to create a cycle you need t

Re: set and dict iteration

2012-09-08 Thread Aaron Brady
On Monday, September 3, 2012 8:59:16 PM UTC-5, Steven D'Aprano wrote: > On Mon, 03 Sep 2012 21:50:57 -0400, Dave Angel wrote: > > > > > On 09/03/2012 09:26 PM, Steven D'Aprano wrote: > > > > >> An unsigned C int can count up to 4,294,967,295. I propose that you say > > >> that is enough iter

Re: set and dict iteration

2012-09-03 Thread Steven D'Aprano
On Mon, 03 Sep 2012 21:50:57 -0400, Dave Angel wrote: > On 09/03/2012 09:26 PM, Steven D'Aprano wrote: >> 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 s

Re: set and dict iteration

2012-09-03 Thread Dave Angel
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. Anoth

Re: set and dict iteration

2012-09-03 Thread Steven D'Aprano
On Mon, 03 Sep 2012 13:04:23 -0700, Aaron Brady wrote: > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady >> wrote: >> >> > We could use a Python long object for the version index to prevent >> > overflow. Combined with P. Rubin's idea to

Re: set and dict iteration

2012-09-03 Thread Aaron Brady
On Monday, September 3, 2012 3:28:28 PM UTC-5, Dave Angel wrote: > On 09/03/2012 04:04 PM, Aaron Brady wrote: > > > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: > > >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > > >> > > >>> We could use a Python long object for the vers

Re: set and dict iteration

2012-09-03 Thread Serhiy Storchaka
On 27.08.12 22:17, Ian Kelly wrote: May I suggest an alternate approach? Internally tag each set or dict with a "version", which is just a C int. Every time the hash table is modified, increment the version. When an iterator is created, store the current version on the iterator. When the iter

Re: set and dict iteration

2012-09-03 Thread Dave Angel
On 09/03/2012 04:04 PM, Aaron Brady wrote: > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: >> >>> We could use a Python long object for the version index to prevent >>> overflow. Combined with P. Rubin's idea to count the number

Re: set and dict iteration

2012-09-03 Thread Aaron Brady
On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: > On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > > > We could use a Python long object for the version index to prevent > > overflow. Combined with P. Rubin's idea to count the number of open > > iterators, most use cases still w

Re: set and dict iteration

2012-09-03 Thread Ian Kelly
On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > We could use a Python long object for the version index to prevent overflow. > Combined with P. Rubin's idea to count the number of open iterators, most use > cases still wouldn't exceed a single word comparison; we could reset the > counte

Re: set and dict iteration

2012-09-02 Thread Aaron Brady
On Monday, August 27, 2012 2:17:45 PM UTC-5, Ian wrote: > On Thu, Aug 23, 2012 at 10:49 AM, Aaron Brady wrote: > > > The patch for the above is only 40-60 lines. However it introduces two new > > concepts. > > > > Is there a link to the patch? Please see below. It grew somewhat during deve

Re: set and dict iteration

2012-08-27 Thread Ian Kelly
On Thu, Aug 23, 2012 at 10:49 AM, Aaron Brady wrote: > The patch for the above is only 40-60 lines. However it introduces two new > concepts. Is there a link to the patch? > The first is a "linked list", a classic dynamic data structure, first > developed in 1955, cf. http://en.wikipedia.org/

Re: set and dict iteration

2012-08-27 Thread Aaron Brady
On Thursday, August 23, 2012 1:11:14 PM UTC-5, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 09:49:41 -0700, Aaron Brady wrote: > > > > [...] > > > The patch for the above is only 40-60 lines. However it introduces two > > > new concepts. > > > > > > The first is a "linked list", a classic

Re: set and dict iteration

2012-08-23 Thread Steven D'Aprano
On Thu, 23 Aug 2012 09:49:41 -0700, Aaron Brady wrote: [...] > The patch for the above is only 40-60 lines. However it introduces two > new concepts. > > The first is a "linked list", a classic dynamic data structure, first > developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . > L

Re: set and dict iteration

2012-08-23 Thread Aaron Brady
On Saturday, August 18, 2012 9:28:32 PM UTC-5, Aaron Brady wrote: > On Saturday, August 18, 2012 5:14:05 PM UTC-5, MRAB wrote: > > > On 18/08/2012 21:29, Aaron Brady wrote: > > > > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > > > >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron

Re: set and dict iteration

2012-08-18 Thread Aaron Brady
On Saturday, August 18, 2012 5:14:05 PM UTC-5, MRAB wrote: > On 18/08/2012 21:29, Aaron Brady wrote: > > > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > > >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > >> > > >> > Is there a problem with hacking on the Beta?

Re: set and dict iteration

2012-08-18 Thread MRAB
On 18/08/2012 21:29, Aaron Brady wrote: On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > Is there a problem with hacking on the Beta? Nope. Hack on the beta, then when the release arrives, rebase your work onto it. I d

Re: set and dict iteration

2012-08-18 Thread Aaron Brady
On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > > Is there a problem with hacking on the Beta? > > > > Nope. Hack on the beta, then when the release arrives, rebase your > > work onto it. I doubt that anything of thi

Re: set and dict iteration

2012-08-17 Thread Chris Angelico
On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > Is there a problem with hacking on the Beta? Nope. Hack on the beta, then when the release arrives, rebase your work onto it. I doubt that anything of this nature will be changed between now and then. ChrisA -- http://mail.python.org/mailman

Re: set and dict iteration

2012-08-17 Thread Aaron Brady
On Thursday, August 16, 2012 9:24:44 PM UTC-5, Steven D'Aprano wrote: > On Thu, 16 Aug 2012 19:11:19 -0400, Dave Angel wrote: > > > > > On 08/16/2012 05:26 PM, Paul Rubin wrote: > > >> Dave Angel writes: > > >>> Everything else is implementation defined. Why should an > > >>> implementation

Re: set and dict iteration

2012-08-17 Thread Aaron Brady
On Thursday, August 16, 2012 9:30:42 PM UTC-5, Paul Rubin wrote: > Steven D'Aprano writes: > > > Luckily, Python is open source. If anyone thinks that sets and dicts > > > should include more code protecting against mutation-during-iteration, > > > they are more than welcome to come up with a

Re: set and dict iteration

2012-08-17 Thread Aaron Brady
On Thursday, August 16, 2012 8:01:39 PM UTC-5, Paul Rubin wrote: > Ian Kelly writes: > > > With regard to key insertion and deletion while iterating over a dict > > > or set, though, there is just no good reason to be doing that > > > (especially as the result is very implementation-specific),

Re: set and dict iteration

2012-08-17 Thread Aaron Brady
On Thursday, August 16, 2012 6:07:40 PM UTC-5, Ian wrote: > On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly wrote: > > > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: > > >> The inconsistency is, if we remove an element from a set and add another > >> during iteration, the new element might

Re: set and dict iteration

2012-08-17 Thread Ulrich Eckhardt
Am 17.08.2012 03:01, schrieb Paul Rubin: Ian Kelly writes: With regard to key insertion and deletion while iterating over a dict or set, though, there is just no good reason to be doing that (especially as the result is very implementation-specific), and I wouldn't mind a more complete low-leve

Re: set and dict iteration

2012-08-16 Thread Paul Rubin
Steven D'Aprano writes: > Luckily, Python is open source. If anyone thinks that sets and dicts > should include more code protecting against mutation-during-iteration, > they are more than welcome to come up with a patch. Don't forget unit and > regression tests, and also a set of timing result

Re: set and dict iteration

2012-08-16 Thread Steven D'Aprano
On Thu, 16 Aug 2012 19:11:19 -0400, Dave Angel wrote: > On 08/16/2012 05:26 PM, Paul Rubin wrote: >> Dave Angel writes: >>> Everything else is implementation defined. Why should an >>> implementation be forced to have ANY extra data structure to detect a >>> static bug in the caller's code? >> F

Re: set and dict iteration

2012-08-16 Thread Paul Rubin
Ian Kelly writes: > With regard to key insertion and deletion while iterating over a dict > or set, though, there is just no good reason to be doing that > (especially as the result is very implementation-specific), and I > wouldn't mind a more complete low-level check against it as long as > it's

Re: set and dict iteration

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 5:11 PM, Dave Angel wrote: > There's an enormous difference between type errors, which affect the low > level dispatch, and checking for whether a dict has changed and may have > invalidated the iterator. If we were really going to keep track of what > iterators are tracki

Re: set and dict iteration

2012-08-16 Thread Dave Angel
On 08/16/2012 05:26 PM, Paul Rubin wrote: > Dave Angel writes: >> Everything else is implementation defined. Why should an implementation >> be forced to have ANY extra data structure to detect a static bug in the >> caller's code? > For the same reason the interpreter checks for type errors at r

Re: set and dict iteration

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly wrote: > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: >> The inconsistency is, if we remove an element from a set and add another >> during iteration, the new element might appear later in the iteration, and >> might not, depending on the hash

Re: set and dict iteration

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: > The inconsistency is, if we remove an element from a set and add another > during iteration, the new element might appear later in the iteration, and > might not, depending on the hash code; therefore comparing the size of the > set between

Re: set and dict iteration

2012-08-16 Thread Paul Rubin
Dave Angel writes: > Everything else is implementation defined. Why should an implementation > be forced to have ANY extra data structure to detect a static bug in the > caller's code? For the same reason the interpreter checks for type errors at runtime and raises TypeError, instead of letting

Re: set and dict iteration

2012-08-16 Thread Dave Angel
On 08/16/2012 02:00 PM, Aaron Brady wrote: > Hello, > > I observed an inconsistency in the behavior of 'set' and 'dict' iterators. > It is "by design" according to the docs. > > ''' > http://docs.python.org/dev/library/stdtypes.html#dict-views > > iter(dictview). Iterating views while adding or

set and dict iteration

2012-08-16 Thread Aaron Brady
Hello, I observed an inconsistency in the behavior of 'set' and 'dict' iterators. It is "by design" according to the docs. ''' http://docs.python.org/dev/library/stdtypes.html#dict-views iter(dictview). Iterating views while adding or deleting entries in the dictionary may raise a RuntimeErr