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
7
votes
3answers
1k views

Merge Sort implemented using iterators

...
7
votes
2answers
460 views

Iterator for BFS binary tree traversal

I implemented an iterator pattern for C# using IEnumerator and IEnumerable. The goal of the implementation is to traverse a ...
5
votes
2answers
71 views

Iterable object on set of ids

For some of the algorithms that I am implementing it turned out to be useful storing ids in order to iterate on objects, while also avoiding having to think about reallocation and invalidation of ...
1
vote
4answers
734 views

Implementing a custom iterator by inheriting from an existing iterator class and overriding operator*

My goal is to write very little code and I want a custom iterator that only changes the behavior of the dereference operator* but copies the rest of the behavior ...
4
votes
1answer
58 views

General use multi-dimensional container using operator[]

This is a followup to a previous question of mine on same subject. Context I want to have a tool that allows to simulate as much as possible a C++ standard container for a multidimensional ...
7
votes
1answer
2k views

Getting serial port list

Needed to get a local serial port list. System.IO.Ports.SerialPort.GetPortNames() returns names but not the descriptions like you can see in Device Manager: ...
3
votes
1answer
305 views

Flatten nested iterables

I wrote a program sometime ago that reads csv files, sorts, reorders and groups their columns/rows' content (with itertools) and later labels the groups using a ...
9
votes
2answers
227 views

Multi-dimensional container using operator[]

This is a late followup to a previous question of mine on same subject. Context: I want to have a tool that allows to use all the C++ goodies (algorithms, for loop on containers, etc.) on a ...
2
votes
1answer
252 views

Implementation of generic unordered list in java

This question is a follow-up question of this question. These features are added to the new class - Generic class User is capable of setting the size ...
6
votes
2answers
926 views

Generic in order traversal iterator for binary trees

This actually started off as member type for the binary_search_tree, but after realizing that it doesn't compare to values or use the value objects inside of it, I ...
7
votes
2answers
60 views

Acts like an iterator, but counts

I’m making a “counting iterator” which emulates a constant container of consecutive values of some integral type. It is mostly boilerplate, going through the list of requirements for different ...
7
votes
1answer
103 views

Custom container for iterating over combinations of elements from multiple sets

Motivated by some SO quesitons [1, 2] I made an attempt at implementing a custom container with a bi-directional custom iterator for iterating over all combinations of elements from multiple sets. I ...
9
votes
2answers
720 views

Determine added, removed and kept items between two lists

My code is determining the difference between two iterables in terms of items that have been addded, removed and kept. The items are assumed to be sortable and there are no duplicates. ...
-6
votes
1answer
108 views

Poor decision of IEnumerable of IEnumerable of IEnumerable [closed]

I wish to improve a class design that causes me readability and performance problems as the code grows. ...
18
votes
8answers
2k views

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

I was reading this question, and the answer that mentioned streams, and a thought had occurred to me. In many cases (at least in my usage) I want to determine if a sequence (or ...
6
votes
1answer
75 views

Iterator over a container with indexing operation

This is a random access iterator that stores an index and a reference to a container. It iterates over any container with indexing operation. It does not have copy assignment / move assignment ...
8
votes
2answers
590 views

Parsing oscilloscope binary data file with C++

Preliminaries I have OWON oscilloscope that is able to record waveform in file in three formats: Text format .txt: the first lines are some general information ...
2
votes
0answers
480 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. ...
10
votes
2answers
1k views

Custom C++ random access iterator for pointers to arrays

I have implemented a custom iterator to iterate over an array that is held by a pointer. The iterator accepts a unit which specifies by which amount the underlying pointer is increased (or decreased) ...
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 ...
4
votes
1answer
113 views

Lazy lists with transformations, using generators & iterators

I built this very-basic lazy list (I'll add more methods as I need them). You provide it an array, a generator or any iterator. It creates a lazy list, which lets you run a pipeline of transformations ...
7
votes
3answers
910 views

Compute Convex Hull

The question asks to compute the convex hull of a set of 2D points. A convex hull is basically a series of consecutive line segments that suffice to enclose all the points in the area. In this ...
5
votes
1answer
3k views

Check if multiple lists contain an element from a large external list

I have a list of lists (many tokenised sentences). For anyone who doesn't know what tokenised sentences are, my list is like so: ...
3
votes
2answers
2k views

Example of adding STL iterator support to custom collection class

I'm trying to create an example of a custom collection with an API meeting the requirements of STL iterator templates, as a learning experience. The collection used here, a ring buffer, is merely a ...
5
votes
1answer
108 views

C++ container — variable byte coded numbers list

I'm writing a container for unsigned integers, which uses variable byte coding. It works but some decisions I took look ugly so I would be glad if you gave me some hints for improving the design. I ...
1
vote
3answers
749 views

Merge sorted lists, removing duplicates

I want to merge two sorted lists of Integers but this is not the general mergesort case because the same number may appear in both lists. (However, each number can only appear once in a particular ...
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, ...
-1
votes
1answer
86 views

Retrieving synonyms from an ontology

My question is about my Ontology which retrieves synonyms from the ontology by using isSynonymOf object property. (Note that my Ontology file is 260 kb and expected to become 500kb). I am ...
8
votes
2answers
953 views

Lazy split and semi-lazy split

Sometimes I need to be able to split data into chunks, and so something like str.split would be helpful. This comes with two downsides: Input has to be strings You ...
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 ...
10
votes
1answer
1k views

Merge n sorted iterators

Over the weekend I was curious about efficiently merging multiple sorted iterators together, and for them to be in sorted order. This is quite like a challenge on HackerRank: You’re given the ...
6
votes
2answers
640 views

Iterator of Container of Container

Based on this question I though I would pull together an iterator that iterated over a container of containers. ...
10
votes
3answers
2k views

Table of Tribonacci sequence using NumPy and PANDAS

What I am trying to accomplish is calculate the Tribonacci numbers and the ratio. I can do this in Excel easy like this. So I tried do the same using Python 3 now. It works and gives such output. ...
4
votes
2answers
419 views

A C++ custom iterator for indirection iteration

This program does not quite conform to the previous related question, yet does basically the same thing: given a collection of elements and a collection of indices, return via an iterator collection ...
1
vote
1answer
74 views

File names to database table

I have files in subfolders on a network drive. I want to create a list of files, and insert that list into an Oracle table. I can successfully iterate through the files in the subfolders and do the ...
8
votes
2answers
2k views

Interleave two lists of strings

I've got a fairly simple task here, but I think it's worth trying to perfect the implementation, because I can probably learn a thing or two about using .NET's enumerables correctly in the process. I ...
5
votes
1answer
134 views

First all zero row of a matrix in C++

The problem of finding the first all zero row in a NxN matrix was featured in a letter to the CACM in 1974 by Frank Rubin who claimed it was a problem for which using a ...
3
votes
1answer
69 views

Loop + Take for repeatedly taking elements from the same collection

I sometimes need to enumerate the same collection multiple times so I wrote an extension that does this for me. I call it Loop. It takes one optional parameter <...
5
votes
2answers
180 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: ...
3
votes
1answer
819 views

Binary search tree in C++ 17 using iterator pattern

I am new to C++ and am attempting to write the following binary search tree using the iterator pattern (and std::optional in C++17): ...
7
votes
2answers
333 views

Lazy string_view splitter range

Trying something out of my comfort zone here, and attempting to implement a D-style range around std::string_view. Looking for any and all suggestions or ...
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 ...
6
votes
3answers
410 views

Find median of two sorted ranges

Given two sorted ranges of elements, compute a median of all the elements in O(log(n+m)) time. This solution contains only one call to std::lower_bound ...
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? ...
1
vote
1answer
111 views

Base64 iterator adaptor for Rust

As a Rust learning exercise, I'm working on implementing cryptopals challenges using iterators to perform lazy processing of data. For the first challenge, this is a base64 decoder implemented as an ...
2
votes
1answer
210 views

Custom iterator and proxy pattern C++

The task was: Create a custom iterator to work with files. I also was told to use a proxy pattern which is new to me. Is there everything I can change to make my code look better? Or maybe I have ...
7
votes
3answers
421 views

Generator iterator with push back function

In a compiler project for an LL(1/2) grammar, I have had a need for a generator iterator with a push back function. I have been surprised not to find any perfectly applicable solution (clean, simple, ...
0
votes
1answer
85 views

Working with cached generator values

I have set of values represented by a class. The class should be initialised with a generator to limit memory use. The class itself is the iterable, having ...
1
vote
1answer
169 views

Stream “on the fly” from matrix

I want to produce a Stream<Pixel> from a Pixel[][]. My code for this is extremely verbose so I suspect I am doing ...
1
vote
1answer
40 views

JointIterable: iterates over all elements of a list of collections

I have this small utility class that allows me to iterate over a series of collections. Please tell me anything that comes to mind. JointIterable.java ...