A technique for generic iteration and its optimization

  • Authors:
  • Stephen M. Watt

  • Affiliations:
  • University of Western Ontario

  • Venue:
  • Proceedings of the 2006 ACM SIGPLAN workshop on Generic programming
  • Year:
  • 2006

Quantified Score

Hi-index 0.00

Visualization

Abstract

Software libraries rely increasingly on iterators to provide generic traversal of data structures. These iterators can be represented either as objects that maintain state or as programs that suspend and resume control. This paper addresses two problems that remain in the use of iterators today: The first problem is that iterators represented as state-saving objects in languages such as C++ or Java typically have logic that is much more complicated than control-based iterators. This paper presents a program structuring technique that allows object-based iterators to be implemented with the same clarity as control-based iterators. The second problem is that the usual implementations of control-based iterators are not sufficiently efficient for high-performance applications. This paper presents a code optimization technique that can be applied to control-based iteration to produce efficient natural loops at the machine code level. Combined, these two results allow iterators for complex data structures to be easily written and efficiently implemented.