As the graph data structure is so central to this chapter, we'll take a look at it in more detail before we move on.
There are a number of ways to implement graphs. In this case, we'll use a variation of an adjacency list, which maps each node to a list of its neighbors. We'll store the nodes in a hash map and keep separate hash maps for each node's data. This representation is especially good for sparse graphs, because we only need to store existing links. If the graph is very dense, then representing the set of neighboring nodes as a matrix instead of a hash table will take less memory.
However, before we start looking at the code, let's check out the Leiningen 2
project.clj file. Apart from the
Clojure library, this ...