Skip to content

Commit

Permalink
add "tsort"
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Sep 25, 2023
1 parent 391dd90 commit 6d34fa1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions content/posts/tsort.md
@@ -0,0 +1,38 @@
+++
title = "tsort"
date = 2023-09-25
summary = "topological ordering for fun and profit"
+++

On the command line, you can use `tsort` to sort a graph into a list (a topological ordering.) Say you have this chart showing what you need to get dressed:

![A graph of dependency relationships among pieces of clothing. It shows you need an undershirt to put on a shirt, shirt to put on a tie, underwear to put on pants, pants to put on a belt, and socks to put on shoes.](/images/tsort-clothes.png)

You can write all those arrows down in a file as dependencies (in order of "X blocks Y," for example "Shirt blocks Tie," "Socks block Shoes.")

```
Shirt Tie
Undershirt Shirt
Shirt Belt
Pants Belt
Underwear Pants
Socks Shoes
Pants Shoes
```

If you pass that to `tsort` you get this, one order in which you could put on clothes to get dressed:

```
Socks
Undershirt
Underwear
Shirt
Pants
Tie
Shoes
Belt
```

It kinda suggests lanes of parallelism, too. For example, you could hypothetically put socks, undershirt, and underwear at the same time. Granted, you'd have to have some machine like in Wallace and Gromit in *The Wrong Trousers*, but that turned out so well for them! 😆

On a more serious note, I've used this to order tasks in projects in [Linear](https://linear.app). Combined with blocker relationships, it makes it clear to everyone which tasks should go first.
Binary file added static/images/tsort-clothes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6d34fa1

Please sign in to comment.