An iterator is an object-oriented programming pattern which for the most part functions similarly to a pointer to an object inside a collection with the added ability to traverse through the collection in a defined manner, agnostic of the actual implementation or even object addresses in physical ...

learn more… | top users | synonyms

1
vote
1answer
35 views

Creating custom random access iterator in C++ 2011

I would like an opinion on my code. I need a random access iterator for my custom container. If I read the C++ 2011 standard, specially chapter 24, I understood that an implementation could be the ...
2
votes
1answer
56 views

How to remove goto statement from iterator

I'm implementing a simple iterator in C# over an xml document, in order to process an xml document in as much a streaming manner as possible. For this reason, I'm using an XmlReader variable in a ...
2
votes
0answers
111 views

Python reversed in C++11

I was playing with C++11 wonderful new features and tried to reimplement a function reversed that would behave just like the one in Python to allow reverse iteration on bidirectional iterables. And to ...
3
votes
3answers
108 views

Most efficient way to iterate through arrays/can I use .times method in place of while method?

I created a quick program to test the precision of randomness generated by the .rand method. The primary question is whether I can use the .times method in place of the while code blocks to increase ...
0
votes
0answers
141 views

How to make a iteration in a for loop faster

I have a list with contentlets and want all languages from every contentlet (I get these with the method languageAPI.getAllValuesByKey(key , contentList). I get a Hashmap and iterate over it. There ...
3
votes
0answers
128 views

Iterator and Generator version of python range function

I have created iterator and generator version of python range function Here is Generator version: def irange(*args): if len(args) > 3: raise TypeError('irange() expected at most 3 ...
2
votes
1answer
177 views

Polymorphic STL foreach without passing the container type

I was trying to figure out how to make a foreach macro for STL containers that is break-able and I came up with this method that uses templates to recognize the container type automatically. Any ...
2
votes
3answers
396 views

Converting base-10 numbers into base-26 letters

I'm writing something that basically takes a bunch of files and renames them into a nice format, such as pic_000.jpeg, pic_001.jpeg, etc. One of the options is to write the incrementation as letters, ...
13
votes
3answers
208 views

infix_iterator code

I've previously posted this on Stack Overflow, and am considering submitting it to Boost for wider distribution, but thought perhaps it would be best to put it up for peer review first, and see if ...
3
votes
2answers
241 views

Is this good Ruby? And is there a Ruby equivalent for Java hasNext() in iterators?

I'm switching to Ruby from Java and so, for exercise purposes, I wrote this verbose leap year Ruby program. The comments express my concerns about Ruby best practices. I'd be glad if some Ruby ...
1
vote
4answers
168 views

Designing an iterator like interface in C

I have a blob whose format is something like below (id1,key1,value1)(id2,key2,value2).... where id is a uint32_t, key and value are null terminated strings. I am looking for an iterator like ...
1
vote
1answer
398 views

Tortoise and hare cycle detection algorithm using iterators in Python

Reading the article in Wikipedia about cycle detection I came across a relatively small code snipped of Floyd's cycle-finding algorithm. I'll put it here to keep everything in one place: def floyd(f, ...
3
votes
1answer
309 views

How to avoid unchecked cast warning in my generic recursive Iterator in Java

Somewhat odd that Java's collection framework has no iterator for recursive data structures... Since I needed something like this, I wrote my own. First of I need recursive elements: public interface ...
2
votes
4answers
1k views

Iterator pattern/iterator class

I have implemented a simple iterator. Just want to check if I have missed anything. interface iterator<E> { boolean hasNext(); E next(); } class Iterator<E> ...
1
vote
1answer
102 views

Can you make this Key-interable view of a List of Maps better?

I have a list of map entries, and I need an iterable that returns the keys. Of course, we could be naive and copy over into a new collection of the desired type, but that's inefficient. So let's ...
7
votes
2answers
355 views

Sudoku Grid special purpose Iterators

Please have a look at these iterators which I use for my Sudoku solver. They behave slightly different from STL iterators and don't implement all functionality that would be needed to use them in a ...