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.

Filter by
Sorted by
Tagged with
6
votes
2answers
718 views

C++17 extract/insert iterators

(Here is a link to this same code on Wandbox) C++17 introduces member functions extract and insert on node-based containers (...
7
votes
1answer
186 views

Preprocessing iterator

After tweaking semantics a lot, it ended up being a very poor object version of std::transform<>() that can be used with other std algorithms. Basically the ...
4
votes
1answer
93 views

Sleeping and invoking a task in Python 2.X and Python 3.X

I'm writing a program that needs to be compatible for both Python 2.X and Python 3.X. My problem is that, because of the differences between these two versions, I'm duplicating code. ...
2
votes
1answer
1k views

2D array view: range-based for loop iterators

I'm working with audio which has a lot of two dimensional sound buffers passed around like this: (float**, int numChannels, int numSamples) I'm looking to ...
3
votes
0answers
73 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 ...
1
vote
1answer
156 views

Heapsort With Full-Scale Genericity

I've written a heapsort implementation. It's generic: generic comparators and sequences with elements of a generic type. The implementation (follows closely chapter 6 from Introduction to Algorithms ...
0
votes
1answer
189 views

C++ implementation of quicksort with iterators (unstable sorting)

Please review the following quicksort implementation. qsort below is intentionally unstable, as partition reoders equal elements....
5
votes
1answer
5k views

Iterator through binary trees (with parent-pointer) without memory-overhead

I have been working on a custom Tree class that enforces certain rules upon insertion and deletion. The implemented tree is a Red-Black-Tree but since the ...
7
votes
4answers
504 views

Double-ended queue and iterators

I have created a double-ended container, but I have doubts about its efficiency in terms of performance. Can you please criticize the code? What can be done extra, such as shortening it? ...
3
votes
1answer
65 views

Get the indices of a range elements by relative order of the values

I've just asked What's the idiomatic way to get the sort order of data, without actually applying it? (or see the original it was found to be a dupe on). So, I want to implement properly what seems ...
3
votes
0answers
130 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 ...
4
votes
2answers
876 views

LinkedList implementation with Iterators in Java

I am a newbie to Java. I will be glad to hear your opinion with regards to this LinkedList implementation. The Iterators are self implemented by my decision: ...
1
vote
2answers
108 views

Displacing an enumerable by a count

What I mean by displacing an enumerable is skipping the first n items, then returning the next n items, then returning the first ...
5
votes
2answers
3k views

Parsing an XML file with elements for keys and values

I'm parsing an XML file that is structured like this: ...
10
votes
3answers
2k views

StackList<T> implementation

I needed a structure that works really similar to the predefined Stack<T> but with a few extra functionalities. Examples include getting the index of value in ...
2
votes
1answer
114 views

Growing potatoes in delayed sequences

In order to grow potatoes I'm implementing the retry pattern. If I fail to grow them, I'd like to try it again later. The first part I've implemented is a collection of delay generators. Their base ...
6
votes
2answers
580 views

An attempt to make a linked list iterator “safe”

I was practicing my C++ routine and decided to code up this simple linked list data structure. Furthermore, I made an attempt to make the list iterator "safe" in the sense that it throws an exception ...
3
votes
1answer
69 views

Handling arguments in a Python-like range() function in JavaScript

I'm making a Python-like range() function (see Python docs) using JavaScript. This function can take from 1 to 3 arguments. There are 3 variables (...
10
votes
2answers
751 views

Iterator for void pointer ranges

In the old days when C was the predominant language under the hood and STL/templates were Alex Stepanov's dream, in order for programmers to achieve generality for functions and data-containers, the <...
1
vote
1answer
78 views

An iterator which behaves like an array with uniform values

I'm implementing an iterator which takes a single value and which you can advance for n times with a dereferencing yielding the single value - but before or after that range of n 'positions' you can't ...
1
vote
1answer
4k views

Converting models into a list of ViewModels [closed]

I have the following code: ...
1
vote
2answers
321 views

Infinitely iterable list class in Python

itertools.cycle is cool, but it has an internal "storage" that uses up memory. And I wanted to practice "tampering" with built-in methods of classes, which is a new ...
10
votes
1answer
146 views

Using generators to print the tree-like structure of a project

The goal of this code is to print the entity tree of a VHDL project. There are a readme and very minimal tests on the github repo. I am trying to refactor the code to use generators in order to ...
7
votes
2answers
386 views

A generic IEnumerator to enumerate COM collections

As I wrapped the VBIDE API, I encountered a number of "collection types" (Windows, CodePanes, ...
1
vote
1answer
773 views

Binary search for random access iterators in C++

I wrote a generic binary search routine in C++ for ranges that are specified by random access iterators. In case the user inputs a range with non-random access iterators, an exception will be thrown. ...
3
votes
3answers
863 views

Lower level exception handling during enumeration

I've got pretty straight forward scenario. I've got a class called FileInformationExtractor and method GetFilesInformation that ...
1
vote
2answers
32 views

Handling iterator exhaustion when not scanning in lockstep

Thus code uses a mergesort-like algorithm to perform an outer join (in the database sense) on two sequences. (It's derived from the ActiveState recipe mentioned in the docstring.) The actual ...
5
votes
1answer
2k views

An iterable implementation of LinkedList

I am curious as to what improvements to my code can be suggested. ...
2
votes
1answer
1k views

IEnumerable to typed Dictionary

Scenario A portable controls/widgets library for Xamarin.Forms (PCL Profile 111) contains a combobox/dropdown/picker control where the ItemsSource property is an <...
3
votes
2answers
341 views

Postponed Prime Sequence in Kotlin

Following my previous unbounded prime generator and a followup by Martin R, I've tested the waters in Kotlin by making an unbounded sieve. To quote Martin R's wonderful explanation of the base ...
5
votes
3answers
334 views

Copy range up to delimiter

The problem I was trying to solve sounded pretty basic, but turned out to be a bit hairy. I need to select some lines of arbitrary length from an input stream (file or standard input) and print them ...
2
votes
2answers
86 views

C# enumerable property like .Any that accounts for nulls

Brief Description: A generic extension method that performs the same function as IEnumerable.Any(), but does not throw an error when passed a parameter with a <...
4
votes
2answers
105 views

Enumerating text (ranges) vertically and horizontally

I'm writing a parser and I need to iterate through text vertically (down to bottom) and horizontally (left to right). This alone would be easy but some text parts need to be rescanned by another ...
7
votes
2answers
424 views

Postponed Prime Sieve in Swift

Motivated by this question, I looked out for other "infinite prime generators", i.e. functions which produce the list of prime numbers in increasing order and do not have an a-priori upper limit (such ...
3
votes
1answer
197 views

C++ Syncronous Poll Wrapper v2

I recently asked for some feedback on my design for a syncronous wrapper around linux sockets and poll Based on the feedback, I created a new (hopefully more idiomatic) design. socket.h ...
1
vote
1answer
66 views

Phishing Project UserIterator Implementation

As I stated in an answer comment on my previous question, the UserIterator has a much larger footprint than I think most people realize. This question is here to further explain the project, the ...
2
votes
3answers
436 views

QuickSort C++ Implmentation using Iterators #2

This is part 2 of the previous question asked which is at - QuickSort C++ Implementation using Iterators. Based on Jerry Coffin's answer, I have made the changes except for using templates. ...
7
votes
2answers
3k views

QuickSort C++ Implementation using Iterators

I implemented quicksort using iterators. I am will be grateful, if someone can review my piece of code. BTW, I am just selecting the last element as the pivot (which I plan to randomize later) I am ...
4
votes
1answer
396 views

Splicing enumerables together

Basically, what I mean by splice is to take an array of Enumerables, take the 1st element from the first one, then the 1st element from the second one, and so forth, until we come back to the 1st ...
4
votes
2answers
669 views

Python lazy dict with iterator in constructor

This question began as an off-topic answer to this question, but the code here serves a different goal. I wrote the following class for the purpose of populating a dict on demand from an iterator. ...
2
votes
1answer
246 views

IEnumerable and Predicate sets in .NET

GitHub Repository Previously: Countable and uncountable sets in .NET (clean version). Thesis There is a full featured support of countable sets in .NET: ...
2
votes
1answer
62 views

ExtensionMethods for iterating hierarchically data structures depth/breath-first

I wrote a few simple extension methods that allow to traverse a hierachically data structure depth-first or breath-first using LINQ: Usage: ...
3
votes
1answer
176 views

C++11 Quicksort any container

As the title says, simple quicksort to help myself get used to C++ templates and iterators. Main concern is whether there's a better way to template so that you can have a simple function (e.g. ...
5
votes
1answer
2k views

Convert a dictionary of iterables into an iterator of dictionaries

I have a user-editable dictionary of content used to fill in a string.Template and I wanted to allow the user to fill the same template with several values at once. ...
1
vote
0answers
343 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 ...
4
votes
1answer
693 views

A Rust iterator to match and replace subsequences

I needed to do transformations on a data stream, not on an element-by-element basis, but on subsequences. This is what I've come up with: https://github.com/peterjoel/rust-iter-replace/blob/master/src/...
4
votes
0answers
224 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 ...
5
votes
2answers
470 views

Standard deviation from iterators

I want this to be similar to the STL algorithms but I don't find it elegant nor concise at all: ...
3
votes
2answers
6k views

Finding a Cartesian product of multiple lists

I came up with an extension method to find a Cartesian product of multiple IEnumerable sets. I was able to achieve lazy enumeration via ...
2
votes
2answers
2k views

Flatten iterator for nested list in python3

flatten.py ...