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)

1
vote
2answers
31 views

multirange iterator

I'm doing some boring math with lot of sums over lot of variables. So, instead of nesting for loops I have decided to use something like this: ...
2
votes
2answers
35 views

Split up an iterable into batches

I was writing a program that had a list of e-mail messages. It needed to group them into batches, with the condition that each batch must have at max 20 messages, and be maximally 50k in size (no ...
8
votes
1answer
65 views

Scala implementation of @rolfl's integer-partitioning algorithm

While reviewing @Martijn's Distinct sums of integers (finding all combinations of positive integers that sum to a given number), I proposed the following solution: ...
7
votes
3answers
917 views

Flags on steroids

What is so bad about [Flags] enum? It does not support IEnumerable<T> anyhow, so to get one we need to use syntax like ...
3
votes
1answer
49 views

Range iterator in ES6 similar to Python and Ruby for

Background and Purpose For those unaccustomed to Ruby, Ruby supports range literals i.e. 1..4 meaning 1, 2, 3, 4 and ...
9
votes
3answers
92 views

Finding if sequential numbers for total exists

Question: Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T Example: ...
10
votes
1answer
93 views

Max element of input iterator range

I came across this SO question on why std::max_element requires a ForwardIterator (as apposed to an ...
8
votes
1answer
93 views

Let's “Iterator” through Fibonacci, forever and ever

Following-up to my previous question, this class is now based on an iterator. The class, instead of forcing the programmer to use up a bunch of memory just to get each progressive number once, they ...
11
votes
1answer
62 views

iterating over the values of a list of ordered dictionaries

I am facing the following problem: I have a special data structure that is a dictionary whose keys are integers (dimensions). The values are also dictionaries whose keys are strings (geometric types) ...
5
votes
0answers
41 views

Using the llvm::iterator_adaptor_base

I'm currently working with the LLVM JIT framework. There is some graph I had to implement for internal cost bench-marking. It has cyclic node dependencies, so I have to use ...
5
votes
2answers
234 views

Mapping & Sorting Randomly Generated Numbers

Below is the assignment I was given and the coding is what I have came up with. I would appreciate criticism on how I did and on ways to have gone differently about it. You want to number your ...
6
votes
2answers
123 views

Random access iterator for custom data type in C++

I am working with an array-like data container through a 3rd party API. So I can not change the container itself to add iterators. There are many different array-like classes, and each have a specific ...
5
votes
1answer
56 views

The final word on contiguous iterators

Following the paradigms of SCARY iterators, there should only be a single iterator-type for contiguous iterators per value-type. Here my code for that iterator, working with C++11+: ...
5
votes
1answer
86 views

Pythonish integer range in Java - follow-up

(See the previous iteration.) I have refactored the Range; now it looks like this: Range.java: ...
12
votes
3answers
921 views

Pythonish integer range in Java

Introduction After getting stuck with a Pythonish integer range in C++, I rewrote the facility in Java. In Python you can say: ...
5
votes
1answer
136 views

Pythonish integer range in C++

Python has that range: >>> range(10, -20, -3) [10, 7, 4, 1, -2, -5, -8, -11, -14, -17] I have this C++ implementation of exactly the same facility: range.h: ...
2
votes
3answers
48 views

Reimplementing enumerate() to produce a sequence or iterator

Apparently it is possible to implement enumerate so it produces a sequence when given a sequence, and produces an iterable otherwise. Sequence can be safely ...
3
votes
2answers
91 views

Singly-linked list implementation with iterators

Taking into account everything you guys told me last time I posted, I came up with this implementation of a singly-linked list, in which the first and last elements are known. I tried to make the ...
8
votes
2answers
186 views

Filtered Iterator

I have written a wrapper for Java's Iterator class using Java 7, which is designed to only iterate items that match a certain filter. When the filter is null, all ...
6
votes
1answer
63 views

Improving multiple assignment using an iterator function

Often I need to perform multiple assignment from a sequence (e.g. from the result of a split()) but with some semantics that, AFAIK, are not available in the ...
3
votes
1answer
76 views

Binary trees in Rust: more iterators! (non-consuming variant)

This is a follow-up to Binary trees in Rust: iterators, where Shepmaster suggested that I implement a non-consuming iterator. This was relatively straightforward. I chose to mirror the design of the ...
5
votes
1answer
110 views

Binary trees in Rust: iterators

This is a follow-up to Basic binary tree manipulation in Rust, where Shepmaster suggested that I implement the Iterator trait for the binary tree. This ended up ...
6
votes
1answer
50 views

Saving and resuming position while iterating over a container

Background: I'm in the process of writing a relatively simple behavior tree driven AI system for a game that I'm working on. Basically, the behavior tree is made up of individual gameplay tasks ...
8
votes
2answers
144 views

Yield statement in a using block from a clarity point of view

I want an opinion of the community about readability and maintainability of the following code. This is quite a rare case when yield statement included in a using construction. I know that this code ...
0
votes
2answers
115 views

Implementation of Vector in C++

This is a simple implementation of vector in C++. Please offer your reviews to improve the code. ...
4
votes
3answers
155 views

Using an IEnumerator without a foreach loop in order to simulate a state machine

I am working with an object that needs to run an ExecuteEffect() method. Sometimes, the ExecuteEffect() only needs to run once, ...
7
votes
3answers
345 views

Implementing xrange

I wanted to learn about Iterable and Iterators and hence thought about getting my hands dirty rather than reading theory and ...
8
votes
2answers
213 views

Iterating over Dungeon Map

I'm working on an RPG so of course I have to have some dungeons. I've got the dungeon generation working, with the output being a DungeonTileType[][]. Now I ...
8
votes
1answer
89 views

Chain multiple containers

Python has itertools.chain(), but C++ has nothing. This is my attempt to implement such a thing. Looking mainly for comments about potentially smarter ways of doing ...
6
votes
3answers
74 views

begin and end overloads for istream_iterator

I wrote this pretty straight forward begin and end overloads for istream_iterator. Is this standards compliant? Any problems with usage? ...
6
votes
2answers
454 views

Implement Java hasNext() and next() in C++

Recently came upon this question asked in interview with major tech company. Implement Java's next and hasNext function in your favorite programming language. Here is the solution I came up ...
5
votes
2answers
610 views

C++ Array with iterators

I wrote an Array class with iterators: ...
3
votes
1answer
53 views

Directed graph path enumerator in Java - follow-up

I have refactored the graph path enumerator. DirectedGraphNode was not changed, so refer to the link above in case you want to have a look at it. The node type is ...
4
votes
2answers
85 views

Directed graph path enumerator in Java

I have this iterator class that expects in its constructor two directed graph nodes, source and target, and upon each ...
3
votes
1answer
91 views

Chaining function for range-based for loop

Motivation: I'm relatively new to C++. I'm writing a function meant to be used with range-based for loops. The goal is to be able to iterate over multiple containers at once, each in turn (essentially ...
3
votes
3answers
95 views

Linked list implementation - follow-up

Follow-up to this question as recommended. Can this code be improved from an OOP paradigm perspective? ...
1
vote
1answer
77 views

OOP paradigm implementation of a linked list

Can this code be improved from an OOP paradigm perspective? ...
6
votes
1answer
70 views

Return the element of collection if the collection contains only one element

Recently I have found in my code several places where I was first gathering some solutions, and then continued processing them only if the solution was unique (solution collection contained only one ...
2
votes
2answers
54 views

Python script to read CSVs and regroup it into the data types I need

This code does the following: Read CSV file and determine sub_type based on series_desc. Turn row into dictionaries ...
2
votes
1answer
88 views

Idiomatic iterator for a linear function

A while back, I asked a question about implementing an idiomatic iterator in C++. I've recently revisited the code, and I'm bothered by the duplication in the begin and end iterators. The code goes ...
0
votes
1answer
67 views

Sieve32, a simple 32 bit sieve returning IEnumerable<uint> using C#

What a difference 1 bit makes! This very fast, simple sieve of Eratosthenes quickly finds 32 bit primes. It uses a memory efficient BitArray for odd numbers – but ...
12
votes
3answers
240 views

Sieve31, my sieve of Eratosthenes returning IEnumerable<int>

This very fast, simple sieve quickly finds 31 bit primes. It uses a memory efficient BitArray for odd numbers. How a 32 bit ...
0
votes
1answer
64 views

A non-static Sieve of Eratosthenes class, version 1

Over the years I’ve seen many C# sieves and despite their varying internals all that I have seen invariably are a static method that returns a List<int>, ...
2
votes
3answers
619 views

Thread-safe Iterator wrapper

Aside: This code assumes a class Option that can be Some or None to represent the presence (Some) or absence (None) of the value it contains. Haskell calls it Maybe. Here is my first pass at ...
1
vote
0answers
57 views

Array slice type in Java - follow-up

See the previous iteration. I have essentially fixed most of the issues mentioned by maaartinus. However, I left the size field as it is. Namely, if the user wants ...
3
votes
1answer
219 views

Array slice type in Java

Edit See the next iteration at Array slice type in Java - follow-up. I have this "slice" type for managing array subranges. It is kind of the same thing as Pythons slice notation, yet I did not add ...
11
votes
2answers
160 views

Streaming int support

This recent question Print Consecutive numbers by comparing two parameters frustrated me because I could not find a convenient way in Java 8 to support the conditions that are required. I answered it ...
0
votes
2answers
148 views

Iterator to remove duplicate element

The code implements custom iterator, which skips duplicate integers. The array expected is to be sorted. ...
2
votes
1answer
72 views

Avoid branching code for degenerate cases in Fibonacci generator

I was writing a simple function that would return the Fibonacci sequence up to the nth term and for whatever reason started wasting a lot of time on it. Here's what I came up with: ...
6
votes
1answer
132 views

Functional tree iteration in Common Lisp

I'm adding some functionality to an existing library of data structures in Common Lisp, with a view to asking the original author if I can take over maintenance and development of it. While the ...