Min Essential Knots is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Min Essential Knots
| API ID | MinEssentialKnots |
| Targets | Functions Packages Subprograms |
| Languages | Ada C# C++ Java Rust |
| Categories | Complexity |
| Cost | Lookup |
Minimum Knots after structured programming constructs have been removed.
Knots and Essential Complexity both start by removing well-structured (single-entry, single-exit) subgraphs from the control-flow graph. Min Essential Knots is just the Knots count of what's left after that reduction, instead of the raw (unreduced) graph.
For example:
void knotsDemo() {
while (1) {
if (a)
break;
if (b || c) {
if (d || e) {
}
else {
if (i)
dosomething();
else if (j)
dosomething();
else if (k)
dosomething();
else {}
}
}
}
}
Reducing knotsDemo collapses the well-structured if (b || c) { ... } chain away, leaving just while (1) { if (a) break; }. That reduced graph has 2 knots (the loop's back edge crossing the break's forward jump), so Min Essential Knots is 2 — much lower than the 6 knots in the unreduced function.
See Max Essential Knots, which also accounts for crossings that reduction hides.
- Ada: Type, Entry, Function, Package, Procedure, Protected, Task
- C#: Method
- C++: Function
- Java: Method
- Rust: Function