classification
Title: itertools roundrobin()
Type: Stage:
Components: Extension Modules Versions: Python 2.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: jackdied, rhettinger
Priority: normal Keywords: patch

Created on 2003-06-17 21:35 by jackdied, last changed 2004-04-30 22:58 by rhettinger. This issue is now closed.

Files
File name Uploaded Description Edit
itertoolsmodule.c.diff jackdied, 2003-06-17 21:35 Modules/itertoolsmodule.c context diff against cvs
test_itertools.py.diff jackdied, 2003-06-27 18:27 Lib/test/test_itertools.py patch
itertoolsmodule.c jackdied, 2003-09-03 00:17 cleaned up patch
libitertools.text.diff jackdied, 2003-09-03 00:18 documentation path
test_itertools.py jackdied, 2003-09-03 00:22 updated test patch
Messages (9)
msg44061 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2003-06-17 21:35
a patch to add the roundrobin() and window() objects to
the itertools module.  Hettinger has already seen the
implementation of roundrobin, but not window.

test_itertools.py in a seperate patch
msg44062 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-06-18 20:11
Logged In: YES 
user_id=80475

*Please post the tests to this patch and close the other patch.

*Add a documentation patch to this patch

*Let's drop the addition of window().  The C code for it is less 
than beautiful and offers only a minimal performance gain 
over the pure python equivalent.  I've added the pure python 
version to the docs so folks can cut and paste it if they need 
it.  Sorry for the wild goose chase (I had expected the C 
version to be much cleaner and faster and that the python 
verions would've been harder -- actual code was needed for 
me to see it).

* In roundrobin_next(), replace the % operator with:
       if (lz->iternum==lz->itersize) lz-iternum=0;

* In roundrobin_next(), remove the extra blank line 
following "long listsize;"

* Fixup the indentation, currently it is a mix of spaces and 
tabs.  It should be just pure tabs.

* Replace the variable name 'lz' with 'rr'.   I should have
changed that in other places too but for new code it 
should be fixed.

* 'unti' is mispelled in the docstring.
msg44063 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2003-06-27 18:27
Logged In: YES 
user_id=591932

added Lib/test/test_itertools.py patch here, deleted old
item that just had that patch in it
msg44064 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2003-06-27 18:33
Logged In: YES 
user_id=591932

pushed to 2.4
I'll put up patches that incorporate rhettinger's feedback
soon, and definitely in time for the 2.4 branch.
msg44065 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-07-01 05:12
Logged In: YES 
user_id=80475

Great.  I look forward to it.
msg44066 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-08-27 05:13
Logged In: YES 
user_id=80475

Jack, are you still working on this one?
msg44067 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2003-09-03 00:25
Logged In: YES 
user_id=591932

The newest triplet of module/test/documentation incorporate
your change suggestions.  That includes the removal of the
window() stuff, so these only contain roundrobin() related
patches.
msg44068 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-04-26 23:42
Logged In: YES 
user_id=80475

Decided not to include this in Py2.4.  

The tool is not sufficiently general.  It has only one use
case and arguably that case is better served with
collections.deque().

The point in favor of the tool is that it cannot be
constructed from other itertools.
msg44069 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-04-30 22:58
Logged In: YES 
user_id=80475

For the record, here a simple and efficient roundrobin task
server based on collections.deque:

def roundrobin(*iterables):
    pending = deque(iter(i).next for i in iterables)
    gettask, scheduletask = pending.popleft, pending.append
    while pending:
        task = gettask()
        try:
            yield task()
        except StopIteration:
            continue
        scheduletask(task)

for value in roundrobin('abc', 'd', 'efgh'):
    print value
History
Date User Action Args
2003-06-17 21:35:14jackdiedcreate