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 | 4099 reads
|
Browse archives
Active forum topics |
Recent comments
36 weeks 10 hours ago
36 weeks 14 hours ago
36 weeks 14 hours ago
1 year 6 weeks ago
1 year 10 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 14 weeks ago
1 year 19 weeks ago
1 year 19 weeks ago