[issue17100] rotating an ordereddict

2013-03-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: For the time being, I want to keep the OrderedDict API simple and avoid feature creep into rotation logic. -- resolution: -> rejected status: open -> closed ___ Python tracker

[issue17100] rotating an ordereddict

2013-02-27 Thread Antoine Pitrou
Antoine Pitrou added the comment: > In the absence of strong use cases, I prefer to keep the API thin > so that OD's remain easy to learn and remember. It could be a separate function or a dedicated subclass if you prefer. But providing it in the stdlib would avoid 3rd party code having to poke

[issue17100] rotating an ordereddict

2013-02-27 Thread Raymond Hettinger
Raymond Hettinger added the comment: My only attraction to adding any of the rotate variants is that they provide functionality that can't be done efficiently by a user without access to the underlying data structure. However, looking only at the API, the methods seem a bit awkward and a bit a

[issue17100] rotating an ordereddict

2013-02-24 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Perhaps for consistency with popitem() and move_to_end() it is worth > to merge rotate_at() and rotate_after() in one method (rotate_to()? > move_to()?) with a boolean parameter. Yes, perhaps. rotate_to(last=False) sounds ok, but perhaps a native English speak

[issue17100] rotating an ordereddict

2013-02-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Perhaps for consistency with popitem() and move_to_end() it is worth to merge rotate_at() and rotate_after() in one method (rotate_to()? move_to()?) with a boolean parameter. -- ___ Python tracker

[issue17100] rotating an ordereddict

2013-02-23 Thread Antoine Pitrou
Antoine Pitrou added the comment: Attaching proof of concept patch for rotate_at() and rotate_after(). I am now conviced that bare rotate() isn't very useful. -- keywords: +patch Added file: http://bugs.python.org/file29213/od_rotate.patch ___ Python

[issue17100] rotating an ordereddict

2013-02-02 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- Removed message: http://bugs.python.org/msg181184 ___ Python tracker ___ ___ Python-bugs-list mailin

[issue17100] rotating an ordereddict

2013-02-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: Please don't rush to make patches. It isn't even clear that this is a good idea. AFAICT, none of the many extant implementation of ordered dictionaries in any language currently implement a rotate operation. FWIW, the iter() and move_to_end() methods are

[issue17100] rotating an ordereddict

2013-02-02 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue17100] rotating an ordereddict

2013-02-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > Does your deque-like implementation preserve O(1) deletion? Ah, OrderedDict should provide O(1) deletion for arbitrary key. Then deque- like implementation should use variable-size chunks and rotate_at() / rotate_after() are possible with O(1). --

[issue17100] rotating an ordereddict

2013-02-02 Thread Antoine Pitrou
Antoine Pitrou added the comment: > > But rotate_at() / rotate_after() can probably be O(1), unless I'm > missing something. > > Hmm, perhaps. But only for current implementation. With more effective > deque-like implementation (when linked list items grouped in > fixed-size chunks) it will be O

[issue17100] rotating an ordereddict

2013-02-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > But rotate_at() / rotate_after() can probably be O(1), unless I'm missing > something. Hmm, perhaps. But only for current implementation. With more effective deque-like implementation (when linked list items grouped in fixed-size chunks) it will be O(n).

[issue17100] rotating an ordereddict

2013-02-02 Thread Antoine Pitrou
Antoine Pitrou added the comment: > > That's O(n), with many spurious insertions and deletions. > > Any implementation is O(n). For rotate() perhaps (but still, it can be more efficient in that it can just move the list head once instead of repeatedly deleting and inserting elements). But rotat

[issue17100] rotating an ordereddict

2013-02-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > That's O(n), with many spurious insertions and deletions. Any implementation is O(n). > deques already allow rotating. I agree that the rotation makes some sense for such collections as deque or OrderedDict (although it is easy implemented in user code).

[issue17100] rotating an ordereddict

2013-02-01 Thread Antoine Pitrou
Antoine Pitrou added the comment: > It is trivial. > > def rotate(od, n): > for i in range(n): > k, v = od.popitem(False) > od[k] = v That's O(n), with many spurious insertions and deletions. > And those functions look too specialized. How so? rotating sounds quite generic

[issue17100] rotating an ordereddict

2013-02-01 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It is trivial. def rotate(od, n): for i in range(n): k, v = od.popitem(False) od[k] = v And those functions look too specialized. -- nosy: +serhiy.storchaka ___ Python tracker

[issue17100] rotating an ordereddict

2013-02-01 Thread Ramchandra Apte
Ramchandra Apte added the comment: Will attach patch when I get free (10 hours from now) -- nosy: +ramchandra.apte ___ Python tracker ___

[issue17100] rotating an ordereddict

2013-02-01 Thread Eric Snow
Changes by Eric Snow : -- nosy: +eric.snow ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.o

[issue17100] rotating an ordereddict

2013-02-01 Thread Antoine Pitrou
New submission from Antoine Pitrou: It can be useful to rotate an OrderedDict (for example when managing a circular playlist). I haven't found any efficient way to do so from user code, without poking at the internals. Actually, I envision three methods: OrderedDict.rotate(self, n): rota