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
3
votes
1answer
54 views

Streamlining series of try-except + if-statements for faster loop processing in Python

I'm processing strings using regexes in a bunch of files in a directory. To each line in a file, I apply a series of try-statements to match a pattern and if they do, then I transform the input. After ...
3
votes
1answer
160 views

Efficiently determine every factor of a given natural number

It's not hard to find all of the factors of a given natural number. Below is a pretty fast python function that can do just that: (Modified version of Steinar Lima's function, https://stackoverflow....
2
votes
1answer
51 views

inroder_iterator for syntax tree of markargs

Introduction It is a spin-off to my compiler creation. Problem Traverse the markargs::syntax_tree in order, e.g. first goes ...
5
votes
1answer
975 views

An iterator wrapper that on dereferencing, returns the value of a member (function)

I wrote a simple iterator wrapper that can be used in e.g. std::find and std::copy and iterator pair constructors to search on ...
3
votes
5answers
112 views

Product iteration while checking for overlaps

This is an extended question to the following question I posted Class scheduling tool with image output Context of previous question: I have a multilayered dictionary that contains information ...
3
votes
1answer
173 views

Internal Zip-like Iterator

My goal was to create an zip-like iterator to selectively iterator over a subset of arrays in a larger manager object, compare itself to any other zip-like iterator, but can be copy constructed from ...
5
votes
1answer
448 views

C++ simple enumerator implementation

I write this enumerator class out of the necessity. I am working on a project that heavily depends on inheritance, abstract (interface) classes, etc. Therefore I ...
5
votes
1answer
421 views

Splitting a UTF-8 string into equal-sized byte-arrays for parallel processing

Based upon a question from Stack Overflow, I wanted to expand on the answer I wrote and define a solution that would support ordering the strings (after processing). So this starts off with a basic <...
2
votes
5answers
697 views

Diff comparison for List<string>

List<string> difference tool for two input List<string> listA and listB Output ...
3
votes
1answer
253 views

Selection algorithm using merge sort and IEnumerable

For educational purposes, I wrote a selection algorithm based on a Merge sort. I would like to improve performance. ...
2
votes
1answer
85 views

JavaScript Python Arrays

Here is an implementation in JavaScript that attempts to resemble Python-like arrays by mimicking slice comprehension for both getters and setters, as well as negative indexing from the end of the ...
4
votes
2answers
389 views

Iterators in JavaScript and remembering position

This is an attempt to write a function link that creates a linked list from an array: ...
4
votes
1answer
220 views

Sorting algorithm, possibly a new one [closed]

I'm a beginner who has never seen a sorting algorithm's implementation and have decided to try make one on my own (can someone tell me if this has been already used?). The fact is I have never used ...
6
votes
4answers
3k views

Splitting a string on delimiter outside of quotes while returning item-by-item

One of the more recent functions I've needed for personal and work purposes is to split a string on a delimiter, but while ignoring the delimiter when inside a quote. Just as well, if within a quote ...
11
votes
3answers
8k views

Extension method replacing elements from an IEnumerable<T> collection

Today I needed a method to replace all 'x' values in a said collection. Since there is no such method by default in .NET I wrote my own: ...
2
votes
1answer
611 views

Single element from iterator

When I was working in Rust this week, I missed kotlin's fun <T> Sequence<T>.single(): T. Basically, calling this function means that you are asserting ...
10
votes
4answers
1k views

random_iterator in C++

This is a small utility that permutes a C++ standard container without modifying the container being iterated: random_iterator.hpp ...
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 ...
5
votes
2answers
161 views

Read lines from a file in chunks

I created a function to read lines from an file into chunks. My hidden agenda in creation this script was in python the yield function in interaction with chunks. The script works fine, but now i ...
7
votes
5answers
729 views

“The Genuine Sieve of Eratosthenes” in C++14

The following C++ code implements the "Genuine Sieve of Eratosthenes" algorithm as described in Melissa O'Neill's classic paper. On my MacBook it computes the first 1,000,000 primes in about 11 ...
5
votes
1answer
377 views

Retrieve the index of the first element using a predicate

I want to change the legacy C-style code by using stl: ...
3
votes
3answers
954 views

Iterator producing unique random numbers in a specified range

I needed an iterator that produced random numbers, never repeating them, in a specified range of 0..max-1 (index for a collection). When the numbers are exhausted it should not have a next anymore. ...
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 ...
5
votes
2answers
527 views

Zigzag Iterator

I've recently solved the LeetCode's "ZigZag iterator" problem: Given two 1d vectors, implement an iterator to return their elements alternately. For example, given two 1d vectors: ...
4
votes
1answer
434 views

Testing procedure with several nested yield statements in Unity3D

I made a small game that does the following: Displays a popup with the instructions of the game Turns on the GUI Start a list of trials for the player For each trial: It shows a symbol Waits for a ...
7
votes
3answers
1k views

Generic List code with Iterator

I was wondering if this implementation of generic list with iterator is correct. The code compiles and goes fine. What would you think shall I improve? (first time I post here, I'm scared). I'm also ...
3
votes
1answer
390 views

Implementation of iterator pattern for any array of elements

I have implemented Iterator pattern: The interface Container.java: public interface Container<T> { Iterator<T> getIterator(); } Interface ...
5
votes
1answer
125 views

Iterator to generate all the words (of a given words) that are one change away

I'm trying to create an iterator, that will generate all the words that are one change away. For example, if my input is "sam", I should get the following words: "aam", "bam", ..."ram","tam",...."...
7
votes
1answer
2k views

Transforming iterator

The question is follow-up to preprocessing iterator. Specification: Given Functor functor (which is Callable) and ...
6
votes
2answers
650 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
182 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
90 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
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 ...
1
vote
1answer
150 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
178 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
500 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
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 ...
4
votes
2answers
837 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
2k 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
113 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
558 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
67 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
703 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: ...