TSORT(1) BSD Reference Manual TSORT(1)

tsort- topological sort of a directed graph

tsort[-flqrvw] [-hfile] [file]

tsorttakes a list of pairs of node names representing directed arcs in a graph and prints the nodes in topological order on standard output. That is, the input describes a partial ordering relation, from whichtsortcomputes a total order compatible with this partial ordering. Input is taken from the namedfile, or from standard input if no file is given. Node names in the input are separated by white space and there must be an even number of node pairs. Presence of a node in a graph can be represented by an arc from the node to itself. This is useful when a node is not connected to any other nodes. If the graph contains a cycle (and therefore cannot be properly sorted), one of the arcs in the cycle is ignored and the sort continues. Cycles are reported on standard error. The options are as follows:-fResolve ambiguities by selecting nodes based on the order of ap- pearance of the first component of the pairs.-hfileUsefile, which holds an ordered list of nodes, to resolve ambi- guities. In case of duplicates, the first entry is chosen.-lSearch for and display the longest cycle. Can take a very long time, as it may need to solve an NP-complete problem.-qDo not display informational messages about cycles. This is pri- marily intended for building libraries, where optimal ordering is not critical, and cycles occur often.-rReverse the ordering relation.-vInform on the exact number of edges broken while breaking cycles. If a hints file was used, inform on seen nodes absent from that file.-wExit with exit code the number of cyclestsorthad to break.

Faced with the input: a b b c b d d f c etsortoutputs: a b c e d f which is one total ordering compatible with the individual relations. There is no unicity, another compatible total ordering would be: a b c d e ftsortis commonly used to analyze dependencies and find a correct build order in a static way, whereas make(1) accomplishes the same task in a dynamic way.

ar(1), lorder(1), make(1) Donald E. Knuth,The Art of Computer Programming, Vol. 1, pp 258-268, 1973.

Atsortcommand appeared in Version 7 AT&T UNIX. Thistsortcommand was completely rewritten by Marc Espie for OpenBSD, to finally use the well- known optimal algorithms for topological sorting. MirBSD #10-current November 1, 1999 1

Generated on 2020-03-27 14:08:39 by `$MirOS: src/scripts/roff2htm,v 1.94 2020/02/16 20:56:25 tg Exp $`

These manual pages and other documentation are copyrighted by their respective writers;
their source is available at our CVSweb,
AnonCVS, and other mirrors. The rest is Copyright © 2002–2020 MirBSD.

This product includes material
provided by **mirabilos**.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.