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
2
votes
1answer
49 views

Compare strings to markup commentary in main text

...
2
votes
1answer
34 views

Adding iterators to C++ sqlite wrapper class

I recently put up my C++ class to wrap the sqlite3 c library here: Thin C++ wrapper for sqlite3 C library One of the suggestions was rather than to specify a vector for arguments to functions instead ...
3
votes
1answer
84 views

Image (Const) Iterator using C++17

I am trying to learn how to correctly implement an iterator (and its corresponding const variant) using a single template, so I would appreciate any criticism to the following code. It's an forward ...
2
votes
1answer
45 views

Implement a range behaviour in Python using iterators

I've been assigned the following Python homework: Implement myrange that acts like range using iterators. Define a function ...
2
votes
0answers
51 views

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
1
vote
2answers
100 views

Racing promises and consuming them in the order of their resolution time

The ideas are When multiple async calls are made, to be able to start consuming from the first resolving one regardless in what order the promises are fired. To construct a modern emitter of async ...
3
votes
3answers
113 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
2
votes
0answers
67 views

A C++ iterator that adds an extra layer of indirection

This iterator is designed with one purpose in mind. If before you had an iterator where you could do int x = *it; now you do ...
4
votes
1answer
110 views

Forward List Implementation

NB: There's a bug with my iterator, apparently. I can't use const_iterator because I get some compiler errors. I know using const...
1
vote
1answer
57 views

How to optimize this majority vote method

I have the following code to do a majority vote for data in a dataframe: ...
0
votes
1answer
66 views

Random Access Iterator Implementation

(This is the Non-const version, I have to implement the const one too). Could someone please review this implementation? This is made for std::vector I'm unsure whether I respected all requirements ...
3
votes
3answers
615 views

Input Iterator implementation

I need some review on my implementation of input iterator. I am currently re-implementing std::vector, and need input_iterator for a specific constructor. Any criticism is much appreciated! Thank you. ...
3
votes
1answer
64 views

Cyclic generator with access to current local state and executes callback after each cycle

I'm working on a Python class that is a cyclic generator, like itertools.cycle, but it offers access to its current state and executes a callback after the ...
4
votes
1answer
103 views

wrapper class for random access iterator to hide template method implementation from header file

I have a set of template functions that have itrator types as template parameters, so can be used with any kind of iterators. std::find can be a good example. Also ...
4
votes
1answer
85 views

Const wrapper for iterator

Edit: added clarification for why I want this, and updated the code since I don't have any answers yet I have a C++11 array-like class which (can be) a wrapper around a random-access iterator. Index-...
6
votes
3answers
665 views

Shorten dict comprehension with repeated operation

dc = {line.split('=')[0]: line.split('=')[1] for line in txt} Below avoids duplication but is even longer: ...
4
votes
1answer
888 views

Convert array of u32 to Vec<u8> in Rust

In Rust, I want to take an array of u32 values, convert each to four bytes in big endian, and concatenate them to yield a ...
6
votes
3answers
1k views

Counting words from stored .md files

The following searches recursively for all the mark down files - i. ending with the extension .md - inside a folder. It then stores the text of the files in an ...
3
votes
1answer
54 views

Get all routes that start with rt_

The code reads all my routes and return to my AJAX request the names of the routes without duplicates and just those that have the "rt_" prefix. ...
3
votes
1answer
166 views

Rust shortest way to find the maximum product of a fixed length substring

I'm trying to code in a Rust a function, that gives the maximum product of adjacent digits. So given the string 123456789, with 3 adjacent digits, the maximum is <...
8
votes
1answer
107 views

base64 iterators

Was a tiny bit bored reading authentication protocols. Needed to clear the mind and read some base64 encode text. So I implemented these iterators that will encode or decode base64 text. Not sure ...
2
votes
0answers
71 views

Async linked list to and from async iterable

I'm working on some stuff that works better with (immutable async) linked lists such as this: ...
3
votes
1answer
78 views

Extending method chaining IEnumerable with Add..If

I'm trying to write an extension (method chaining) for playing around a bit. What I made work is an extension to add an item to the list (what is pretty easy): ...
2
votes
1answer
93 views

Generate binary image using coordinate vectors

I have a matrix M of size [n_rows, n_cols] and a list of x and ...
4
votes
0answers
321 views

Deep map, Python

Goal: apply fn to every element of an arbitrarily nested iterable (tuple, list, dict, np.ndarray), including to iterables. Ex: ...
3
votes
2answers
106 views

Deep len, Python

Goal: find total number of elements in a nested iterable of arbitrary depth. My shot: ...
2
votes
2answers
130 views

Fibonacci iterator

I've implemented the following Fibonacci iterator: lib.rs ...
0
votes
1answer
56 views

Ensure queue is in ascending order

The program reads in a queue of integers and returns determines whether or not it is valid (ascending). How can this code be improved? I assume iterator include statement is unnecessary? ...
2
votes
1answer
52 views

Iterator-Pattern for an iterator that returns one objects that changes

I wrote an algorithm that returns all k-sized subgraphs of another given graph. Because I don't want to make the runtime of the next() call of the iterator depended on k, I don't want to return a new ...
1
vote
4answers
706 views

Exercise: Design a Stack

Exercise: Design a Stack A Stack is a data structure for storing a list of elements in a LIFO (last in, first out) fashion. Design a class called Stack with three methods. ...
5
votes
1answer
162 views

`zip` operator to iterate on multiple container in a sign

I worked out a zip operator similar to Python's, because I didn't find one in std. It allows to use range-based ...
2
votes
1answer
80 views

template iterable numeric range class with multiple min/max inclusion modes

Problem my code solves: Lack of lightweight numeric range classes which can tell if arbitrary values lie inside them, supporting more than just simple exclusive max modes and integers, and that ...
3
votes
1answer
83 views

Splits up two comma separated items, if they exist

This method splits up two comma separated items, if they exist, and increments the amount if the are already in the list; otherwise add the item to the list I want to know if this code can be ...
2
votes
1answer
70 views

Compare length of iterator with as few `next` calls as possible. How can I deduplicate this code?

I'm writing a few simple functions that compare the length of an iterator to an integer, returning as early as possible. Right now I have: ...
0
votes
1answer
46 views

c# QuadTree yielding properly [closed]

I have implemented a QuadTree of my own, and I'm afraid I didn't use yield properly when I query my tree, my fear is that I create O(HN) iterators. Could you direct me how to better improve the ...
3
votes
0answers
50 views

Populate a list with combinations of one- and two- object functions

I have a nested set of for loops which achieves the desired outcome, but I don't know if it is the most efficient / pythonic way of populating this list. I would ...
9
votes
2answers
626 views

Manipulating list values in python

I wrote a function that I use to preprocess pandas dataframes before running them through a machine learning model. The function works perfectly, however I don't think it's the most pythonic way to ...
4
votes
1answer
66 views

Summation Over Lines in a File (Advent of Code 2018 Day 1)

Preface: I am learning Rust through the Advent of Code The task is to read lines from a file, parse each as an integer, then provide a summation of all the numbers. My solution looks like this: <...
3
votes
1answer
173 views

Iterate through Expression Tree

I'm trying to build an iterator (enumerator) that can select specific elements in an Expression tree by traversing the tree and deferring further iteration until ...
8
votes
2answers
3k views

C++17 zip iterator compatible with std::sort

Here are ~100 lines of code implementing three classes (ZipRef, ZipIter, Zip) which should ...
10
votes
2answers
1k views

Iterator for traversing a tree [v2]

this is an update of the implementation after I followed the feedback from Iterator for traversing a tree. After that I did changed quite a bit on the design and decided to ask for another round of ...
3
votes
1answer
101 views

Iterator for traversing a tree

What I want to achieve is the following: ...
4
votes
1answer
124 views

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
1
vote
1answer
32 views

Bidirectional numeric (floating point) sequence iterator

I wanted a neat iterator that will always give me neat sequence of step spaced numbers. This is what I came up with, but I am a bit skeptical that I covered all ...
2
votes
0answers
878 views

Combining two nested for loops into one [closed]

Description What this does is it takes a randomly generated 64x64 stack and checks for overlap within the 64x64 array. Here is an example: https://imgur.com/a/kkPRzhn. Each color is its own ...
2
votes
1answer
474 views

A simple priority queue in Java via linked list sorted by priority keys

Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
1
vote
1answer
61 views

A GapHelper static class to create unique (non-existing) size restricted names

I am working with a 3th party library which has following interface defined for a processing task: ...
7
votes
1answer
261 views

Map unique raw words to a list of code words

Problem Write a function that replaces the words in raw with the words in code_words such that the first occurrence of each ...
3
votes
1answer
75 views

Aggregation on list forEach and maps improvals

I am using a function in a SpringBoot @RestController, with Lombok This function is an intermediate result that permit me to do an aggregation between two classes. This 2 classes are: ...
1
vote
1answer
242 views

c++ python like range function to use in for loops

It's a simple range function that works like python range and it is only a syntactic sugar for the usual for loop if we want to operate on numbers in the range from 1 to 10 (1 ... 9) we use this code ...

1
2 3 4 5
8