Iterating Over Objects
 
 
 

The AlIterator class simplifies writing code that must operate on lists of objects. AlIterators significantly reduce the overhead associated with using wrappers to walk lists of items. The applyIterator() methods on many classes will traverse a list of objects in the most efficient method possible and may reuse wrappers. For example, using AlSet::firstMember() and AlSetMember::nextSetMember() may require O(nlog n) operations to traverse the entire Alias set. Using the iterator requires only O(n) operations. See the documentation in the AlIterator class.

Explicit traversals can be optimized through the use of the ‘nextD’ and ‘prevD’ destructive methods.

AlCurveCV* cv; if ( cv = curve->firstCV() ) { 	do 		{ ... do something ... } 	while( sSuccess == cv->nextD()); 	delete cv; }

The statement cv->nextD() causes the current wrapper to reference the next CV in the curve. No additional memory is allocated, and in general the destructive methods will run faster than the non-destructive methods.

Whenever possible, one should use the AlIterator class when traversing a collection of objects. Not only will the traversal be as quick as possible, but the memory management is taken care of. The wrappers passed to the iterator’s callback function are destroyed by the class and need not be freed explicitly.