@@ -352,20 +352,38 @@ and a quick way to check whether a particular edge was present.
352352 Unfortunately, those are not the only operations we need.
353353
354354A build system like Contingent
355- is going to focus its processing on nodes, not edges.
356- When building a particular asset like ``api.html ``
357- it will need quick access to all of the incoming edges,
358- so that it can adjust them as it learns which resources
359- the build routine uses this time around,
360- and will also need access to the outgoing edges
361- so that any downstream tasks can be re-executed
362- if the content of ``api.html `` is changed.
363- Our set-of-tuples does not make this easy.
364- The entire set would need to be traversed
355+ needs to understand the relationship between a given node
356+ and all the nodes connected to it.
357+ For example, when ``api.rst `` changes,
358+ Contingent needs to know which assets
359+ are affected by that change, if any,
360+ in order to minimize the work performed
361+ while also ensuring a complete build.
362+ To answer this question —
363+ what nodes are downstream from ``api.rst ``? —
364+ we need to examine the *outgoing * edges from ``api.rst ``.
365+ But building the dependency graph requires that
366+ Contingent be concerned with a node's *inputs * as well:
367+ what inputs were used, for example,
368+ when the build system assembled the output document ``tutorial.html ``?
369+ It is by watching the input to each node that
370+ Contingent can know that ``api.html `` depends on ``api.rst `` but
371+ that ``tutorial.html `` does not.
372+ As sources change and rebuilds occur,
373+ Contingent uses the incoming edges of each changed node
374+ to remove potentially stale edges and relearn which resources
375+ the build routine uses this time around.
376+
377+ Our set-of-tuples does not make answering
378+ either of these questions easy.
379+ If we needed to know the relationship between ``api.html ``
380+ and the rest of the graph,
381+ we would need to traverse the entire set
365382looking for edges that start or end at the ``api.html `` node.
366383
367- Python’s only associative data structure is the dict.
368- We could use a dict to group edges for quick lookup by node::
384+ An associative data structure like Python's dict
385+ would make these chores easier
386+ by allowing direct lookup of all the edges from a particular node::
369387
370388 {'tutorial.rst': {('tutorial.rst', 'tutorial.html')},
371389 'tutorial.html': {('tutorial.rst', 'tutorial.html')},
@@ -402,12 +420,27 @@ for every one of the edges in which it is involved. ::
402420 'api.rst': {'api.html'},
403421 }
404422
423+ Notice that ``outgoing `` represents directly in Python syntax
424+ exactly what we drew in Figure 1 earlier:
425+ the source documents on the left
426+ will be transformed by the build system into the
427+ output documents on the right.
428+ For this simple example each source points to only one output —
429+ all the output sets have only one element —
430+ but we will see examples shortly where a single input node
431+ has multiple downstream consequences.
432+
405433Every edge in this dictionary-of-sets data structure
406434does get represented twice,
407435once as an outgoing edge from one node
408- and again as an incoming edge to another node.
436+ (``tutorial.rst `` → ``tutorial.html ``)
437+ and again as an incoming edge to the other
438+ (``tutorial.html `` ← ``tutorial.rst ``).
439+ These two representations capture precisely the same relationship,
440+ just from the opposite perspectives of the two nodes
441+ at either end of the edge.
409442But in return for this redundancy,
410- it supports the fast lookup that Contingent needs.
443+ the data structure supports the fast lookup that Contingent needs.
411444
412445The Proper Use of Classes
413446=========================
0 commit comments