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 ...

learn more… | top users | synonyms (1)

1
vote
1answer
20 views

Simple and concise new iterator design

I came up with a new iteration pattern for a C++ API that aims at simplifying client code. Basically, when developers have an iterable object myCollection, they ...
6
votes
1answer
44 views

Return the element of collection if the collection contains only one element

Recently I have found in my code several places where I was first gathering some solutions, and then continued processing them only if the solution was unique (solution collection contained only one ...
-1
votes
0answers
14 views

Generic Flattened Iterator Implementation without using a Stack of Iterators

An implementation of a generic flattened iterator for flattening an iterator of iterators upto any composite level without using a stack for holding the iterators: ...
2
votes
2answers
47 views

Python script to read CSVs and regroup it into the data types I need

This code does the following: Read CSV file and determine sub_type based on series_desc. Turn row into dictionaries ...
2
votes
1answer
72 views

Idiomatic iterator for a linear function

A while back, I asked a question about implementing an idiomatic iterator in C++. I've recently revisited the code, and I'm bothered by the duplication in the begin and end iterators. The code goes ...
0
votes
1answer
41 views

Sieve32, a simple 32 bit sieve returning IEnumerable<uint> using C#

What a difference 1 bit makes! This very fast, simple sieve of Eratosthenes quickly finds 32 bit primes. It uses a memory efficient BitArray for odd numbers – but ...
6
votes
0answers
64 views

Sieve31, my sieve of Eratosthenes returning IEnumerable<int>

This very fast, simple sieve quickly finds 31 bit primes. It uses a memory efficient BitArray for odd numbers. How a 32 bit ...
0
votes
1answer
47 views

A non-static Sieve of Eratosthenes class, version 1

Over the years I’ve seen many C# sieves and despite their varying internals all that I have seen invariably are a static method that returns a List<int>, ...
2
votes
3answers
199 views

Thread-safe Iterator wrapper

Aside: This code assumes a class Option that can be Some or None to represent the presence (Some) or absence (None) of the value it contains. Haskell calls it Maybe. Here is my first pass at ...
1
vote
0answers
43 views

Array slice type in Java - follow-up

See the previous iteration. I have essentially fixed most of the issues mentioned by maaartinus. However, I left the size field as it is. Namely, if the user wants ...
3
votes
1answer
55 views

Array slice type in Java

Edit See the next iteration at Array slice type in Java - follow-up. I have this "slice" type for managing array subranges. It is kind of the same thing as Pythons slice notation, yet I did not add ...
11
votes
2answers
149 views

Streaming int support

This recent question Print Consecutive numbers by comparing two parameters frustrated me because I could not find a convenient way in Java 8 to support the conditions that are required. I answered it ...
0
votes
2answers
69 views

Iterator to remove duplicate element

The code implements custom iterator, which skips duplicate integers. The array expected is to be sorted. ...
2
votes
1answer
65 views

Avoid branching code for degenerate cases in Fibonacci generator

I was writing a simple function that would return the Fibonacci sequence up to the nth term and for whatever reason started wasting a lot of time on it. Here's what I came up with: ...
4
votes
0answers
69 views

Functional tree iteration in Common Lisp

I'm adding some functionality to an existing library of data structures in Common Lisp, with a view to asking the original author if I can take over maintenance and development of it. While the ...
3
votes
1answer
90 views

Modern C++ compliant insertion sort

This is a kind of follow up to my previous sort implementation question with specific questions to insertion sort, and Modern C++ idioms. Anybody seeing this post can see how I got to this modern ...
5
votes
2answers
223 views

Doubly linked list: iterator/pointer arithmetic

I'm using a doubly linked list container I've written as the working example. The textbook I'm using is from 2001, so feel free to point out where later versions of the C++ standard should be used ...
2
votes
1answer
45 views

Extract incomplete weeks from a DateTime collection

The code below attempts to extract incomplete weeks from a List<DateTime>. For example, a list containing all the days in Jan 2015 would result in the 5th to ...
3
votes
1answer
51 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
74 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! ...
1
vote
1answer
93 views

Efficient use of LINQ - Indexing

I have a Class with a List of objects, and those objects contain a list which has lists to objects in the first class, and I'm trying to quickly index them. Simplified: ...
10
votes
2answers
189 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
33 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 ...
2
votes
1answer
44 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
130 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
77 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
111 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
143 views

Functions taking iterables: peaks, compress, and skipper

I am just testing out a few small functions for learning purposes: ...
7
votes
1answer
93 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
206 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
241 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 ...
3
votes
2answers
440 views

Uppercase the initial char of every string in a list

My problem is that I have a sequence, potentially infinite, of strings. Let's suppose it to be {"Mickey Mouse", "Bugs Bunny", "Winnie the Pooh"} I have to make ...
6
votes
3answers
161 views

Classify values depending on predicates

I've to do a generic method Classify<T> that, given a sequence of elements of type T and an arbitrary number of ...
4
votes
2answers
254 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 ...
4
votes
1answer
80 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
1k 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 ...
3
votes
1answer
49 views

Bottleneck encountered returning records for my grid

I am using MVC 4.0/C#/EF4.0 and I have a grid page that grabs results that are filtered, sorted and paged. It's filtering results from a table that has 45,000 records. How do I improve performance? ...
4
votes
1answer
110 views

Sieve prime generator C++

I had some issues with the behavior of the iterator in my prime generator: ...
3
votes
3answers
215 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 ...
5
votes
2answers
955 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
49 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 ...
1
vote
2answers
149 views

Double Inclusive Range step by step

I've written a method to obtain an IEnumerable from a start point, end point and step. Similar to Enumerable.Range() but for doubles and not fixed step. ...
2
votes
1answer
261 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
102 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
235 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 ...
5
votes
3answers
254 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
305 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 ...
10
votes
3answers
3k views

Method returning IEnumerable<T> should ToList() or not

I can't decide whether my method that returns an IEnumerable<T> should itself be lazy or whether it should build a list and return that. I often opt for the ...
4
votes
1answer
34 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
160 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) ...