A queue is another fundamental data structure; it is heavily used in many contexts. Queuing up tasks is a very common requirement. For example, if we look at the producer/consumer pattern, we see that both the producers and consumers communicate using a queue.
You will find many examples of queues being used in practice. Here's one of them: In an actor framework, an actor sends a message to another actor. These messages are enqueued in the recipient actor's mailbox, which is a queue.
Message brokers use queues to order and distribute messages to consumers. Priority queues are used by operating system schedulers so high priority tasks are handled before tasks that are low on priority.
In this chapter:
We will look at functional, persistent FIFO queues. The persistent FIFO queue has an interesting design, using list prepending techniques.
We will also look at priority queues, which are implemented using heaps. We will familiarize ourselves with the core data structure and how...