Abstract
We introduce the Random Access Zipper (RAZ), a simple, persistent data structure for editable sequences. The RAZ combines the structure of a zipper with that of a tree: like a zipper, edits at the cursor require constant time; by leveraging tree structure, relocating the edit cursor in the sequence requires log time. While existing data structures provide these time bounds, none do so with the same simplicity and brevity of code as the RAZ. The simplicity of the RAZ provides the opportunity for more programmers to extend the structure to their own needs, and we provide some suggestions for how to do so.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
In short, these levels represent the heights of uniformly randomly chosen nodes in a full, balanced binary tree. See Sect. 3.
References
AdelsonVelskii, M., Landis, E.M.: An algorithm for the organization of information. Technical report, DTIC Document (1963)
Aragon, C.R., Seidel, R.: Randomized search trees. In: 30th Annual Symposium on Foundations of Computer Science, Research Triangle Park, North Carolina, USA, 30 October–1 November 1989, pp. 540–545 (1989)
Bayer, R.: Symmetric binary B-trees: data structure and maintenance algorithms. Acta Inf. 1, 290–306 (1972)
Bender, M.A., Cole, R., Demaine, E.D., Farach-Colton, M., Zito, J.: Two simplified algorithms for maintaining order in a list. In: Möhring, R., Raman, R. (eds.) ESA 2002. LNCS, vol. 2461, pp. 152–164. Springer, Heidelberg (2002). https://doi.org/10.1007/3-540-45749-6_17
Dietz, P.F., Sleator, D.D.: Two algorithms for maintaining order in a list. In: Proceedings of the 19th Annual ACM Symposium on Theory of Computing, New York, USA, pp. 365–372 (1987)
Hammer, M.A., et al.: Incremental computation with names. In: Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2015, Part of SPLASH 2015, Pittsburgh, PA, USA, 25–30 October 2015, pp. 748–766 (2015)
Hammer, M.A., Khoo, Y.P., Hicks, M., Foster, J.S.: Adapton: composable, demand-driven incremental computation. In: ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2014, Edinburgh, United Kingdom, 09–11 June 2014, p. 18 (2014)
Hinze, R., Paterson, R.: Finger trees: a simple general-purpose data structure. J. Funct. Program. 16(2), 197–217 (2006)
Huet, G.: The zipper. J. Funct. Program. 7, 549–554 (1997)
OCaml Batteries Team: OCaml batteries included. https://github.com/ocaml-batteries-team/batteries-included. Accessed 12 July 2016
Pugh, W.: Skip lists: a probabilistic alternative to balanced trees. In: Dehne, F., Sack, J.-R., Santoro, N. (eds.) WADS 1989. LNCS, vol. 382, pp. 437–449. Springer, Heidelberg (1989). https://doi.org/10.1007/3-540-51542-9_36
Pugh, W., Teitelbaum, T.: Incremental computation via function caching. In: POPL (1989)
Sleator, D.D., Tarjan, R.E.: Self-adjusting binary trees. In: Proceedings of the 15th Annual ACM Symposium on Theory of Computing, Boston, Massachusetts, USA, 25–27 April 1983, pp. 235–245 (1983)
Stucki, N., Rompf, T., Ureche, V., Bagwell, P.: RRB vector: a practical general purpose immutable sequence. In: ICFP 2015 (2015)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2019 Springer Nature Switzerland AG
About this paper
Cite this paper
Headley, K., Hammer, M.A. (2019). The Random Access Zipper. In: Van Horn, D., Hughes, J. (eds) Trends in Functional Programming. TFP 2016. Lecture Notes in Computer Science(), vol 10447. Springer, Cham. https://doi.org/10.1007/978-3-030-14805-8_9
Download citation
DOI: https://doi.org/10.1007/978-3-030-14805-8_9
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-14804-1
Online ISBN: 978-3-030-14805-8
eBook Packages: Computer ScienceComputer Science (R0)