IteratorTools icon indicating copy to clipboard operation
IteratorTools copied to clipboard

Fix stack problem

Open Cortado-J opened this issue 6 years ago • 0 comments

Hi Michael (or is it Mike!) I was working on some swift that does combinations & permutations. I then discovered itertools in python and then found this repo. Great that you've done this. I wanted to check how it handled larger arrays. I found it crashed if I went up to a combination of 8 elements. This pull request shows the test that crashes and a fix. The problem was that in 4 places in the code you have next() as recursive and when arrays get large this fills up the stack (or maybe it's the heap? !). The solution is to put a while true { } loop in the routine and use continue. This stops the stack (heap?) being used and it's fine.

Cortado-J avatar Nov 10 '18 11:11 Cortado-J