Skip to main content

FileBranching

Struct FileBranching 

Source
pub struct FileBranching {
    pub branch_points: u32,
    pub functions: u32,
    pub peak_cyclomatic: u16,
    pub cognitive: u32,
    pub cognitive_nesting_weight: u32,
    pub has_module_unit: bool,
    pub has_synthetic_units: bool,
}
Expand description

Branching totals for one file: the quantity that survives extraction, and the number of units now holding it.

A per-function cyclomatic ceiling constrains a partition, not a quantity. McCabe gives a function 1 + one increment per decision point, so across a set of units the summed cyclomatic score is functions + branch_points. Moving an if from one function into a new one removes an increment from the first and adds it to the second: branch_points is unchanged and functions rises. Reporting the two terms separately is what distinguishes branching that left from branching that only moved.

Module scope is accounted for. Extraction pushes a root frame per program and emits it as a synthetic <module> unit whenever it branches, so a branch hoisted out of a function to the top level of the module keeps its increment in branch_points and adds one to functions, exactly as moving it into a new function would. A fall in branch_points is therefore a statement about the file’s measured decision points, not about a partition.

Fields§

§branch_points: u32

Summed weight of Cyclomatic contributions. The conserved quantity.

§functions: u32

Number of accounted units. The tax a split adds.

§peak_cyclomatic: u16

Highest single-unit cyclomatic score. Reported, never a verdict input: a split lowers it by construction.

§cognitive: u32

Summed weight of Cognitive contributions, excluding PropCount and HookDensity. Both are cognitive-only with no cyclomatic counterpart, and PropCount records the excess over a floor, so it is superlinear in a split: one 14-prop component contributes +10 while the same props across two 7-prop components contribute +3 and +3. Including them would move this number with both branch_points and nesting flat. This therefore does NOT equal the sum of FunctionComplexity::cognitive.

§cognitive_nesting_weight: u32

Summed nesting over the same cognitive contributions. Extraction rebases nesting to zero on every new frame, so a cognitive improvement that shows up here and not in branch_points came from repartitioning, not from removing branching.

§has_module_unit: bool

Whether one of the counted units is the module body. Its branching is real and belongs in branch_points, but it is not a function anyone split into, so a consumer judging whether a file was split must not count it towards the function tax.

§has_synthetic_units: bool

Whether the file carried a synthetic template unit that these counts exclude. When it did, the numbers describe the file’s script only, so a consumer must not present them as describing the whole file. The synthetic <module> unit is NOT a template unit and does not set this flag: it is counted like any other unit, because module-scope branching is part of the script the numbers describe.

Implementations§

Source§

impl FileBranching

Source

pub fn from_units(units: &[FunctionComplexity]) -> Self

Aggregate one file’s units.

Synthetic template units are excluded: they are suppressed entirely when trivial, which would silently move any denominator that counted them. Suppression is deliberately not consulted, so a fallow-ignore-next-line complexity comment cannot remove a unit’s branches from the total.

The synthetic <module> unit IS counted. It carries the file’s module-scope decision points, and leaving it out would restore the blind spot that let a branch disappear from the total by being hoisted out of every function.

Source

pub const fn implied_cyclomatic(&self) -> u32

Summed cyclomatic score implied by the identity functions + branch_points.

Equals the direct sum of FunctionComplexity::cyclomatic over the same units unless a unit saturated u16, which is the one way the identity can break.

Trait Implementations§

Source§

impl Clone for FileBranching

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FileBranching

Source§

impl Debug for FileBranching

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'__de> Decode<'__de> for FileBranching
where '__de:,

Source§

impl Default for FileBranching

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Encode for FileBranching

Source§

impl Eq for FileBranching

Source§

impl PartialEq for FileBranching

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FileBranching

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DecodeOwned for T
where T: for<'de> Decode<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.