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 ...
2
votes
0answers
7 views
AdjacentElementsIteratorAdaptor for Random Access Iterators
Inspired by this comment I decided to implement an iterator adaptor that takes another iterator and returns each element and a given number of its neighbors.
The final solution should be applicable ...
4
votes
2answers
45 views
Iterating over the lines of a stream
This structure is supposed to iterate over the lines of an input stream, using std::getline. Any remark is welcome!
...
0
votes
0answers
22 views
Add list obj to list obj [on hold]
i'm newbie in java, learning to do some staff with collection, etc. My task is, add list of student's which i've input from keybroad to group. And dont have any idea, how to realize it. So, shall i've ...
6
votes
1answer
86 views
Lazy String.Split
C#'s String.Split method comes from C# 2.0, and lazy operations weren't a feature back then. The task is to split a string according to a (single) separator. Doing ...
1
vote
0answers
24 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
26 views
Adaptive cyclic database iterator
This is a bit tricky to explain. I'm trying to model a cyclic iterator that would return the next available DataSource(SQL). So infinite calls would just pick the ...
2
votes
1answer
96 views
Iterator requirements for a fake container supporting C++11 range-based for
Around a year ago, I wrote this Stack Overflow answer where I suggested an idea to replace deeply nested loops with a single iterable virtual-container object that "contains" all the indices.
The ...
3
votes
1answer
64 views
Wrapping WinAPI FindNextVolume as std iterator
This is my first attempt at creating an STL-style iterator. Is this code ok?
...
0
votes
2answers
84 views
Two permutation iterators for classes in Python with and without a generator
I am just testing out a couple of small classes for learning purposes. Here is my current working code:
...
3
votes
3answers
71 views
Functions taking iterables: peaks, compress, and skipper
I am just testing out a few small functions for learning purposes:
...
7
votes
1answer
71 views
Serialization: Escape Input String
In Json strings characters can be escaped with \\.
Here is an iterator that can read such strings and convert the escaped characters to UTF-8
...
2
votes
2answers
117 views
Bag data structure (a set that can store multiple copies of items)
I am trying to make my class a bit cleaner, especially some of its methods like Count, __add__, ...
5
votes
2answers
225 views
Interleaving values from several iterables
I am new to Python and am trying to see if there is a cleaner way to write my code. The following code take iterables as parameter it produces the first value from the first parameter, then the first ...
4
votes
2answers
184 views
Sorting function that also works with containers having only forward iterators
I was playing around with some code trying to implement a sorting algorithm in C++ that also works with singly linked lists. Since the merge routine of mergesort only scans forward, implementing a ...
1
vote
0answers
45 views
Reversing the “words” of a container with a bidirectional iterator
I posted another snippet of code a few weeks back when I started learning C++. Here's my second try now that I have some time to play with this again. The goal is to write a generic algorithm for ...
3
votes
2answers
172 views
Custom iterator for a linked list class
I have made a LinkedList class. This is a singly-linked-list and I want to make a forward_iterator for this class without using ...
4
votes
1answer
102 views
Sieve prime generator C++
I had some issues with the behavior of the iterator in my prime generator:
...
3
votes
3answers
132 views
Iteritems on a slice of a Python list
iteritems on a dict can useful.
Occasionally iteritems is useful for a slice of a list and ...
3
votes
1answer
235 views
StreamIterable - create an iterable from a Java 8 Stream
This seems like an easy thing to mess up, so I'd be grateful if you could think of any edge-cases that I've missed.
...
1
vote
1answer
46 views
Homogenising iterator and const_iterator
I've reworked (for C++11) a section of PyCXX which contained an almost identical iterator and const_iterator.
I would like to ...
2
votes
1answer
140 views
ArrayList for Shop implementatin
Problem statement:
Design a system for the following scenario:
An item list contains item code, name, rate, and quantity for several items.
Whenever a new item is added in the list ...
2
votes
2answers
77 views
Handling thread interruptions in a directory iterator
This code is code written on a whim to help $someindividual asking for such a thing on $somechatmedium; what is needed is a way, ...
11
votes
2answers
173 views
Elementwise iterator adaptor
There are many C++ implementations of the Euclidean vector. I.e., a vector in what is typically a 3- or 4-dimensional space. Something along the lines of
...
4
votes
3answers
223 views
Cyclic iterator in both directions
I am trying to make a cyclic iterator that works backwards and forwards. getNext() gets the next array item, getPrevious() gets ...
8
votes
2answers
164 views
Self-made linked list iterator
I recently made a linked list for myself, the code of which was posted here, if anyone would be interested. Now, as the next task, I had to make an Iterator for my ...
1
vote
0answers
52 views
Unrolled linked list with iterator [closed]
I'm making an unrolled linked list (linked list with an array of 50 in each Node) for a class project with an iterator. In addition, whenever more than half of the arrays are unused (they would all be ...
4
votes
1answer
30 views
Finding the next XML element
I am looking for a better way to do a while cycle with the variable update.
The background is that I'm writing a StAX-line XML reader in JavaScript and want to ...
7
votes
2answers
143 views
Array-like container for uints shorter than 8 bits (Rev 1)
This is a follow-up to Array-like container for uints shorter than 8 bits
In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
11
votes
1answer
146 views
Array-like container for uints shorter than 8 bits
Follow-up: Array-like container for uints shorter than 8 bits (Rev 1)
First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
7
votes
2answers
329 views
Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used)
BEFORE YOU READ: this link should be included when you just don't like the format of the question and for those that read this question for the first time, the link may give you the idea what happened ...
4
votes
2answers
68 views
Custom MultiIterator with type filter
I'll start with giving a bit of background as there are many classes involved and I can't attach all of them because that would make this question wildly too long. For the curios they can be found at ...
3
votes
1answer
110 views
Return one particular element first, when iterating a lua table
I wish to iterate through a Lua table, but want to get one particular element first always (its key is known beforehand).
Since the pairs function does not guarantee the order of a table's elements, ...
4
votes
1answer
98 views
Python caching generator
Is this the correct way to cache a generator in Python, without iterating over it right away (for example using list() over it)?
...
15
votes
1answer
239 views
CircularListCursor - an efficient circular cursor on any list
I have decided to create my own CircularListCursor, because I wanted some abstraction and a ListIterator<E> couldn't give ...
2
votes
1answer
90 views
Graceful way to iterate through two arrays and build a master array?
params[:controller_id].each do |cid|
params[:zone_number].each do |pzn|
zone_ids << Zone.find_by_controller_id_and_number(cid,pzn).id
end
end
I have ...
11
votes
1answer
357 views
Custom iterator implementation returning OpenCV Mat
I have written an adapter class that allows iteration over the rows of a Mat object from OpenCV. For those interested, here is the Mat documentation, but the ...
6
votes
3answers
211 views
Iterator of iterator
Given an iterator of iterators, return all of the elements from the iterators in order. Looking for code review, optimizations, and best practices. Verifying complexity to be \$O(n)\$, where \$n\$ is ...
5
votes
3answers
184 views
Iterator for a list of objects
Given a list of objects, return an iterator for such a list. Looking for code-review, optimizations and best practices. Verifying complexity to be O(n) where n is sum of all objects, including ...
5
votes
3answers
761 views
Linked list with iterators
This is my second linked list implementation for review. I rewritten pretty much all of this and have added iterators, sentinels and The Rule of Five.
Please let me know what's wrong with it; I am ...
4
votes
1answer
107 views
Container which iterates a range or a list
I have made some composited container Range which accepts either a min/max range as a std::pair or a set of integers as a ...
4
votes
2answers
139 views
3
votes
5answers
542 views
A deduplicating iterator
Implement an iterator(Generic) which skips an element if it is equal to the previous element. e.g : AAABBCCCCD, produces ABCD.
Below is my attempt. Please suggest improvements.
...
11
votes
3answers
7k views
Simple Example of an Iterable and an Iterator in Java
I was a TA for a first-year Java programming course this year. As a very simple example of iterables/iterators, I wrote the following code for the students. I am curious if any styling or other ...
10
votes
2answers
793 views
Using a Pythonesque range() generator function with the Java foreach loop
Now that we have the nice new foreach loop in Java, the old-style loop looks ugly be comparison.
I like the way Python has a ...
2
votes
2answers
2k views
Iterator for binary tree - pre, in, and post order iterators
Implemented iterator for a binary tree and "pre" "in" and "post" order flavors. I'm looking for code review, best practices, optimizations etc.
...
7
votes
2answers
389 views
Iterator class using a square list
I am trying to implement squarelist by using iteration that points to the head element. I've create this iterator class to make my iterator id directional. I just want to see if I implemented it ...
2
votes
2answers
4k views
Creating linked list data with iterator pattern
I've created a linked list to use it in SquareList. I've started to create a linked list based on just that. I want my class to follow the iterator pattern. How can it be improve to use vector ...
3
votes
1answer
142 views
Serializing tabular data in ruby — is map, flatten, hash the correct approach?
I wanted a hash which lets me reference Japanese syllables by their romanized names. In hindsight I could have searched for an existing one column table, but I wanted to improve my ruby by writing a ...
1
vote
0answers
152 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 ...
8
votes
1answer
324 views
Iterator adaptor for iterators returning tuple-like values
Today, I will require your help to improve an iterator adapter. The goal of the adapter (I called it get_iterator) is to adapt ...