iterator

how to do only selected folders with a PHP 5 iterator?

I am trying to use the PHP recursive directory iterator to find php and html files in order to list those by date. The code used is as follows: $filelist = array(); $iterator = new RecursiveDirectoryIterator( $this->_jrootpath ); foreach(new RecursiveIteratorIterator($iterator) as $file) { if ( !$file->isDir() ) { if ( preg_...

Difficulties with Iterator and Generics in Binary Search Tree Implementation

Hey everyone! I am studying Data Structures in java and I am having difficulty with using generics in Binary Search Trees. For our assignment we are to implement a Binary Search Tree using nodes that contain a parent, left and right node as well as a data value. The data value in our case takes the form of a Pair object. This is what i...

Using a Set Iterator in C++

When I try to use a set iterator in debug mode in C++, I get an error that says "map/set iterator not dereferencable". I don't understand because I thought dereferincing was how you are supposed to use an iterator. The code looks like this: set<int>::iterator myIterator; for(myIterator = mySet.begin(); myIterator != mySet.end(); ...

split a generator/iterable every n items in python (splitEvery)

I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition: splitEvery :: Int -> [e] -> [[e]] @'splitEvery' n@ splits a list into length-n pieces. The last piece will be shorter if @n@ does not evenly divide the length of the list. The basic version of this works fine, but I want a version tha...

split a string using find_if

Hi, I found the following code in the book "Accelerated C++" (Chapter 6.1.1), but I can't compile it. The problem is with the find_if lines. I have the necessary includes (vector, string, algorithm, cctype). Any idea? Thanks, Jabba bool space(char c) { return isspace(c); } bool not_space(char c) { return !isspace(c); } vector<s...

Java: Iterating HashMap - Algorithm needed

Hi! I have a question. I have a list of names, say 8 names: Joe, Bob, Andrew, Bill, Charlie, Sarah, Ann, Victor The count of names might differ**. 1) What should I use as name list? Hashmap, Vector, Hashtable, List, ArrayList? 2) I need to match them up like this: Joe-Bob, Andrew-Bill, Charlie-Sarah, Ann-Victor. Could you please sho...

parallel computation for an Iterator of elements in Java

I've had the same need a few times now and wanted to get other thoughts on the right way to structure a solution. The need is to perform some operation on many elements on many threads without needing to have all elements in memory at once, just the ones under computation. As in, Iterables.partition is insufficient because it brings al...

Iterator and constant interator in C++

Whats the difference? I want to be able to see if an element is in a HashMap and I just found out that if I do h[element], it will return the default element if it is not found, and not null. How would I use the iterator find method to see if the element is there? Thanks ...

i don't know __iter__ in python,who can give me a good code example.

my code run wrong class a(object): def __iter(self): return 33 b={'a':'aaa','b':'bbb'} c=a() print b.itervalues() print c.itervalues() Please try to use the code, rather than text, because my English is not very good, thank you ...

i don't know why iter(not __iter__) function use in this place,what is the mean of iter in this code.

i don't know "self._iterator = iter(self._container)"in next code. in django.http : class HttpResponse(object): def __iter__(self): self._iterator = iter(self._container) return self def next(self): chunk = self._iterator.next() if isinstance(chunk, unicode): chunk = chunk.encode(sel...

Using Javascript RegExp to replace each match with an iterating number

I want to replace empty lines in my string with an iterating number e.g. replace String: "My first line My second line My third line" with " 1 My first line 2 My second line 3 My third line" I can match and replace these lines using var newstring = TestVar.replace (/(^|\n\n)/g, "\nhello\n"); However I'm struggling to ad...

How does this class implement the "__iter__" method without implementing "next"?

I have the following code in django.template: class Template(object): def __init__(self, template_string, origin=None, name='<Unknown Template>'): try: template_string = smart_unicode(template_string) except UnicodeDecodeError: raise TemplateEncodingError("Templates can only be constructed fro...

the value of iterator

i created a map. i want to print the index of the key to a file using the itr in the map. this is what i mean: map <string,int> VendorList; VendorList[abc] = 0; VendorList[mazda] = 111; VendorList[ford] = 222; VendorList[zoo] = 444; map <string,int>::iterator itr=VendorList.find("ford"); fstream textfile; textfile << itr; if i put i...

hasNext in Python iterators?

Haven't Python iterators got a hasNext method? ...

C++ range/xrange equivalent in STL or boost?

hello Is there C++ equivalent for python Xrange generator in either STL or boost? xrange basically generates incremented number with each call to ++ operator. the constructor is like this: xrange(first, last, increment) was hoping to do something like this using boost for each: foreach(int i, xrange(N)) I. am aware of the for loo...

How to associate an iterator to a collection in OCaml

I have these two classes in OCaml class type ['a] collection = object method add : 'a -> unit method clear : unit -> unit method iterator : unit -> 'a iterator method remove : 'a -> unit end class type ['a] iterator = object method hasNext : unit -> bool method next : unit -> 'a end And I need to cr...

Why was GetEnumerator() stored in a separate interface from IEnumerator ?

Hi, I was wondering why the GetEnumerator() method was factored out of IEnumerator and placed in IEnumerable. It seems to me that it would make more sense to keep all of the enumerator methods in IEnumerator. Thanks, Scott ...

Why use string::iterator rather than index?

string::iterator it; for (it = str.begin(); it < str.end(); it++) cout << *it; cout << endl; Why not: for (int i = 0; i < str.size(); i++) cout << str[i]; cout << endl; It seems that string::iterator does not provide range check either. Why should we use string::iterator rather than index? Thanks. ...

PHP Lazy Load Iterator

I have an iterator class that loops over an array of objects and lazily loads from the database when it needs to (when it's not loaded into memory). Problem is this is iterating around 200,000 times and I found out from here: http://www.garfieldtech.com/blog/magic-benchmarks that the iterator interface is incredibly slow. Would anyone k...

Stepping through all permutations one swap at a time

Given a list of n distinct items, how can I step through each permutation of the items swapping just one pair of values at a time? (I assume it is possible, it certainly feels like it should be.) What I'm looking for is an iterator that yields the indices of the next pair of items to swap, such that if iterated n!-1 times it will step t...