Questions tagged [iterator]

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 memory. Iterators may be further limited in particular traversal directions.

25 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
0answers
60 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 ...
4
votes
0answers
37 views

Apply arbitrary action during recursive generator function

I've got this recursive generator function. It will traverse an object looking for "leafs", any keys that don't point to sub-objects. Then it applies one of two actions on the leaf and yields it. Any ...
4
votes
2answers
168 views

Lag Lead Enumerator

I had a need to do a look-ahead and look-behind when enumerating though and IEnumerable. Here is a classic situation: ...
4
votes
0answers
51 views

Iterator structure for block and interlace counting schemes

We have a set of time slices, in the order of 50. Throughout this question I will use 6. We group these slices into blocks, in this example the block size is 2. Then we want to iterate through all ...
4
votes
0answers
423 views

Selection sort implementation in C++ iterator approach

I am trying to learn the C++ way of writing code. I was wondering if this code could be improved or if there are any major mistakes. Is it ok how I name the variables? ...
4
votes
0answers
222 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
3
votes
0answers
33 views

Rust Iterator that correlates a slice with itself

In my effort to learn Rust I've tried implementing an Iterator that splits up a buffer in two halves, and correlates both halves by sliding them over each other with different positions (lags). You ...
3
votes
0answers
188 views

Helper trait for modularizing iterator chains which involve grouping items in tuples

The itertools::Itertools::tuples method from the itertools crate appears to be limited in the aspect that the trait ...
3
votes
0answers
50 views

SparseGraph: A representation of a mathematical graph

I'm working on a SparseGraph which reflects the mathematical notion of a graph. All code included here works in all of the basic test cases that I've tried. However, I'm most concerned about the ...
3
votes
0answers
72 views

A matrix class for objects other than numbers

I'm in the process of writing a matrix like container to store objects. Despite many existing matrix implementations, I won't do numerics. Instead I want to replace a ...
3
votes
0answers
128 views

Converting a get-by-index function into an iterator for use with STL algorithms

This is a solution to Advent of Code 2016, Day 8. The tricky part of this problem is that you have to be able to rotate both the rows and columns of a two-dimensional array. Rotating a row is easy ...
3
votes
0answers
143 views

An iterator returning all possible solutions to n-queen problem in Java

(See the next iteration.) Given a positive integer \$n\$, I have an iterator that returns all possible solutions to \$n\$-queens problem one by one: QueenIterableV1.java: ...
2
votes
0answers
26 views

Using best practice with complex iteration

I'm new to Rust so I'm still learning how to use best practice in complex examples. Below is some code I've used in one of my programs, a simple implementation of a standard neural network. Here is ...
2
votes
0answers
40 views

Iterator that groups elements of its source

I wrote an iterator to access the pixel in an packed image. It works, but it is slow. 1.Are there any mistakes that can be avoided and might lead to better speed? 2.Are there any pitfalls that ...
2
votes
0answers
478 views

Iterator for custom List class

I have extended a custom list class I have been working on with a Iterator class. I have not used std::iterator as a base class as it will be deprecated in C++17. ...
2
votes
0answers
141 views

Implementing a tabular pretty-print using Java 8 Stream API

About six years ago I implemented a simple tabular pretty-print Java class that mostly simulated MySQL CLI query result tables. I don't really like it because it was implemented in a, I believe, ...
2
votes
0answers
36 views

DynamicIterable

I have written this DynamicIterable that can be used as a Lazy Iterable, where you give it a Supplier<T> of something and ...
2
votes
0answers
283 views

An iterator returning all possible solutions to n-queen problem in Java - follow-up

(See the initial iteration.) Now I have slightly improved performance of the iterator. Whenever we have set a queen at a particular board cell, the previous iteration sacrifices \$\mathcal{O}(n)\$ ...
1
vote
0answers
51 views

itertools.produce reduced and filtered

I need to generate list of all allowable test combination values of of actor, action and ...
1
vote
0answers
337 views

Scan over parameter iterator for model simulation

I'm writing a small Python application that performs model simulation for many different parameters. The iterator of parameters isn't completely known ahead of time. Rather, the iterator needs to ...
1
vote
0answers
123 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 ...
1
vote
0answers
62 views

A context-based partition_copy

I recently posted a question on Stack Overflow asking how I could go about implementing a context-based partition copy. I actually came up with my own solution, but I would like to see if it could be ...
1
vote
0answers
542 views

REST Response: Checking for Success and Error

I thought this was pretty slick - maybe not, I just wanted to share and maybe get some feedback: As part of a REST client class: Accepts the JSON response from REST or REST-like service, searches ...
0
votes
0answers
57 views

An iterator returning all possible permutations of a list in Java - follow-up

(See the previous and initial iteration.) My main attempt here was to get rid of monolithic code and split the implementation into smaller methods when applicable and do more extensive commenting. ...
0
votes
0answers
49 views

Deferred Iteration in TypeScript

I've published a new TypeScript library currently in beta, and was hoping to get feedback on certain aspects of it, particularly implementation details for improving the performance of deferred ...