User loginNavigation |
A little insight on iterators/accumulatorsIf you've used a popular OO language chances are you've dealt with iterators. For example if I wanted to append to a list while traversing it back and fourth, template operator ++ () m.fwd = m.pos == m_cont.size() - 1 ? 0 : m_pos == 0 ? 1 : m_fwd; return m_fwd ? *m_cont[(m.pos++)] : *m.cont[(m_pos--)];
The key to this iterator is that whenever the upper bounds or lower bounds is met the iterator simply traverses in its the opposite direction. Decent in situations where one would want to compare array values having added or removed new ones - the drawback however is knowing when to stop. In addition, one must be somewhat aware of its length throughout. Otherwise it can lead Another example would be the nthElement iterator. This basically says that after each iteration we sort its indice in the array. Consquently sample dataset: set = [n, n - 1, n + 1] *set ++; // returns n set.at(0) // returns n - 1 // [n - 1, n, n + 1] Lastly consider a usage iterater. In a nutshell this says every time a resource uses an indice it's usage count increments. This practice involves keeping a pointer to the next ideal location in the array. Consider: dataset = [1,2, .. , n] consume(dataset[1]) *dataset ++; // returns 2 given we've used its indice the most In this example the array itself needn't be rearranged the iterator could simply keep a pointer to the next location. Anyway for brevity that's it for now. By nadhamid at 2013-09-27 17:29 | LtU Forum | previous forum topic | next forum topic | other blogs | 3701 reads
|
Browse archivesActive forum topics |
Recent comments
7 weeks 3 days ago
7 weeks 5 days ago
7 weeks 6 days ago
14 weeks 6 days ago
20 weeks 4 days ago
20 weeks 5 days ago
21 weeks 4 days ago
24 weeks 2 days ago
25 weeks 5 days ago
25 weeks 6 days ago