Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-28 Thread Josiah Carlson
If one doesn't care about slicing, the obvious implementation using a dictionary and two counters works great for a deque with random indexing. Well... except for the doubling in memory usage. - Josiah On Wed, Jan 27, 2010 at 4:15 PM, Raymond Hettinger raymond.hettin...@gmail.com wrote: On

[Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Nick Coghlan
Steve Howell wrote: There is also the possibility that my initial patch can be refined by somebody smarter than myself to eliminate the particular tradeoff. In fact, Antoine Pitrou already suggested an approach, although I agree that it kind of pushes the boundary of sanity. :) I'm actually

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Alex Gaynor
On Wed, Jan 27, 2010 at 4:50 PM, Nick Coghlan ncogh...@gmail.com wrote: Steve Howell wrote: There is also the possibility that my initial patch can be refined by somebody smarter than myself to eliminate the particular tradeoff. In fact, Antoine Pitrou already suggested an approach, although I

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Daniel Stutzbach
On Wed, Jan 27, 2010 at 3:50 PM, Nick Coghlan ncogh...@gmail.com wrote: I'm actually wondering if you could apply some of the implementation strategies discussed here to grant O(1) random access to arbitrary elements of a deque. I haven't looked at the deque code in a long time, but I

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Raymond Hettinger
Are you free to chat about this in IRC? I completely unconvinced that there are use cases for wanting face random access to the i-th element of a large deque that is changing sizes on each end. The meaning of the 20th index changes as the data moves. It becomes pointless to store indices to

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Nick Coghlan
Alex Gaynor wrote: I don't see how that's possible. The linked list is a pretty well known data structure and arbitrary lookups are O(n) in it. Using the unrolled-linked-list data structure python uses you can make it faster by a constant factor, but not O(1). There are other structures

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Maxim Khitrov
On Wed, Jan 27, 2010 at 5:06 PM, Daniel Stutzbach dan...@stutzbachenterprises.com wrote: On Wed, Jan 27, 2010 at 3:50 PM, Nick Coghlan ncogh...@gmail.com wrote: I'm actually wondering if you could apply some of the implementation strategies discussed here to grant O(1) random access to

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Maciej Fijalkowski
FWIW, deque indexing for small deques is already O(1) and somewhat fast.  You only get O(n) degradation (with a small contant factor) on large deques. Hi. For small dequeues (smaller than a constant), you have to have O(1) operations, by definition :-) Cheers, fijal

Re: [Python-Dev] O(1) random access to deque? (Re: patch to make list.pop(0) work in O(1) time)

2010-01-27 Thread Raymond Hettinger
On Jan 27, 2010, at 3:55 PM, Maciej Fijalkowski wrote: FWIW, deque indexing for small deques is already O(1) and somewhat fast. You only get O(n) degradation (with a small contant factor) on large deques. Hi. For small dequeues (smaller than a constant), you have to have O(1)