scitools.com

← Metric catalog

Max 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.

Max Essential Knots

API ID: MaxEssentialKnots
Languages: Ada, C#, C++, Java, Rust
Targets: Functions, Packages, Subprograms

Maximum Knots after structured programming constructs have been removed.

The reduction Essential Complexity uses can hide crossings that existed inside a collapsed region — a jump whose original path passed through part of what's now a single placeholder statement. Max Essential Knots estimates those as "boundary knots": for each jump remaining in the reduced graph, it checks whether the collapsed region it crosses could have hidden such a crossing. Since each potential crossing is detected from both ends of the jump, the raw boundary knot count is halved before being added to Min Essential Knots: MaxEssentialKnots = MinEssentialKnots + BoundaryKnots / 2, capped at the Knots count of the original, 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 {}
      }
    }
  }
}

For knotsDemo, the reduced graph (while (1) { if (a) break; }) has a Min Essential Knots of 2. The while loop's own jump back to its condition spans over where the collapsed if (b || c) { ... } region used to be, so it's flagged as a possible hidden crossing: a boundary knot (raw count of 2, halved since it's detected from both ends of the jump) contributing 2 / 2 = 1, for a Max Essential Knots of 2 + 1 = 3.

See Min Essential Knots for the knot count without that estimate, and Knots for the count on the unreduced graph.


Targets By Language: Configuration: