一句话:提出 Synchrony 迭代抽象,使多有序集合的同步迭代和通用数据库连接可用推导式表达。
现代语言常提供推导式(comprehension)语法以提升集合操作可读性,但其通常对应嵌套循环,难以表达多个有序集合的高效同步迭代,如低选择率数据库连接的线性时间算法。本文提出 Synchrony fold 刻画同步迭代:核心是关联两集合序关系的单调 isBefore 谓词,以及识别匹配对的 antimonotonic canSee 谓词。限制 Synchrony fold 使其外延表达力等同于推导式,得到 Synchrony generator;它仍保留足够内涵表达力以高效同步迭代有序集合。作者证明其是数据库 merge join 的自然推广,并扩展至更一般的连接。最后导出 Synchrony iterator,其表达力与 generator 相同,但更契合推导式,使此类算法可自然用推导式表达。
Abstract Modern programming languages typically provide some form of comprehension syntax which renders programs manipulating collection types more readable and understandable. However, comprehension syntax corresponds to nested loops in general. There is no simple way of using it to express efficient general synchronized iterations on multiple ordered collections, such as linear-time algorithms for low-selectivity database joins. Synchrony fold is proposed here as a novel characterization of synchronized iteration. Central to this characterization is a monotonic isBefore predicate for relating the orderings on the two collections being iterated on and an antimonotonic canSee predicate for identifying matching pairs in the two collections to synchronize and act on. A restriction is then placed on Synchrony fold, cutting its extensional expressive power to match that of comprehension syntax, giving us Synchrony generator . Synchrony generator retains sufficient intensional expressive power for expressing efficient synchronized iteration on ordered collections. In particular, it is proved to be a natural generalization of the database merge join algorithm, extending the latter to more general database joins. Finally, Synchrony iterator is derived from Synchrony generator as a novel form of iterator. While Synchrony iterator has the same extensional and intensional expressive power as Synchrony generator, the former is better dovetailed with comprehension syntax. Thereby, algorithms requiring synchronized iterations on multiple ordered collections, including those for efficient general database joins, become expressible naturally in comprehension syntax.