Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Persistence
- 3 Some Familiar Data Structures in a Functional Setting
- 4 Lazy Evaluation
- 5 Fundamentals of Amortization
- 6 Amortization and Persistence via Lazy Evaluation
- 7 Eliminating Amortization
- 8 Lazy Rebuilding
- 9 Numerical Representations
- 10 Data-Structural Bootstrapping
- 11 Implicit Recursive Slowdown
- A Haskell Source Code
- Bibliography
- Index
3 - Some Familiar Data Structures in a Functional Setting
Published online by Cambridge University Press: 17 September 2009
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Persistence
- 3 Some Familiar Data Structures in a Functional Setting
- 4 Lazy Evaluation
- 5 Fundamentals of Amortization
- 6 Amortization and Persistence via Lazy Evaluation
- 7 Eliminating Amortization
- 8 Lazy Rebuilding
- 9 Numerical Representations
- 10 Data-Structural Bootstrapping
- 11 Implicit Recursive Slowdown
- A Haskell Source Code
- Bibliography
- Index
Summary
Although many imperative data structures are difficult or impossible to adapt to a functional setting, some can be adapted quite easily. In this chapter, we review three data structures that are commonly taught in an imperative setting. The first, leftist heaps, is quite simple in either setting, but the other two, binomial queues and red-black trees, have a reputation for being rather complicated because imperative implementations of these data structures often degenerate into nightmares of pointer manipulations. In contrast, functional implementations of these data structures abstract away from troublesome pointer manipulations and directly reflect the high-level ideas. A bonus of implementing these data structures functionally is that we get persistence for free.
Leftist Heaps
Sets and finite maps typically support efficient access to arbitrary elements. But sometimes we need efficient access only to the minimum element. A data structure supporting this kind of access is called a priority queue or a heap. To avoid confusion with FIFO queues, we use the latter name. Figure 3.1 presents a simple signature for heaps.
Remark In comparing the signature for heaps with the signature for sets (Figure 2.7), we see that in the former the ordering relation on elements is included in the signature while in the latter it is not.
- Type
- Chapter
- Information
- Purely Functional Data Structures , pp. 17 - 30Publisher: Cambridge University PressPrint publication year: 1998