MyNixOS website logo
Description

Queue data structures.

Queue data structures, as described in

  • Okasaki, Chris. "Simple and efficient purely functional queues and deques." Journal of functional programming 5.4 (1995): 583-592.

  • Okasaki, Chris. Purely Functional Data Structures. Diss. Princeton University, 1996.

A queue has a "back" where new elements are enqueued, and a "front" where elements are dequeued in the order that they were enqueued (last in, first out).

The queues provided in this library also support an "enqueue at front" operation, because the underlying representations happen to support it, so you might technically refer to these data structures as output-restricted deques.

In this library, it is helpful to think of the "front" being on the left, because (though the direction is arbitrary) we are consistent throughout, where it matters:

  • List conversion functions associate the head of a list with the front of a queue.

  • The append operator xs <> ys creates a queue with xs in front of ys.

  • The Show instances draw the front of the queue on the left.

Under "ephemeral" (or "single-threaded", or "linear") usage, wherein one does not need to refer to an old version of a data structure after mutating it:

  • EphemeralQueue is 2.5x faster than and allocates 0.50x as much memory as Queue.

  • Queue is 2.6x faster than and allocates 0.40x as much memory as Seq (from containers).

(These numbers vary from benchmark to benchmark and machine to machine. Always perform your own experiments!)

While it is certainly common to use a queue ephemerally, it is unusual for a Haskell data structure to require ephemeral usage to achieve its stated bounds. A refactoring or change in requirements might cause surprising changes in performance. That is why EphemeralQueue has a longer name and module name. When in doubt, use Queue.

queues.

GitHub CI Hackage Stackage LTS Stackage Nightly Dependencies

Metadata

Version

1.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows