architecture/network/remove

Raised when node removal targets a node that is not in the network.

architecture/network/remove/network.remove.errors.ts

NetworkRemoveNodeNotFoundError

Raised when node removal targets a node that is not in the network.

NetworkRemoveStructuralAnchorError

Raised when node removal targets an input or output anchor node.

architecture/network/remove/network.remove.utils.types.ts

ERROR_CANNOT_REMOVE_ANCHOR_NODE

Error emitted when trying to remove structural anchor nodes.

ERROR_NODE_NOT_IN_NETWORK

Error emitted when target node is not part of the network.

FIRST_REMOVED_NODE_INDEX

Index for selecting first spliced node.

NetworkRemoveProps

Internal network properties accessed during remove operations.

NODE_NOT_FOUND_INDEX

Sentinel index used when node is not found.

NODE_TYPE_INPUT

Node type literal for input anchors.

NODE_TYPE_OUTPUT

Node type literal for output anchors.

NodeConnectionSnapshotContext

Snapshot of node adjacency prior to removal.

NodeRemovalContext

Immutable context for validated node-removal request.

ReconnectEndpointPairContext

Endpoint pair for reconnecting bridged paths.

architecture/network/remove/network.remove.utils.ts

Node removal utilities.

This module provides a focused implementation for removing a single hidden node from a network while attempting to preserve overall functional connectivity. The removal procedure mirrors the legacy Neataptic logic but augments it with clearer documentation and explicit invariants.

High‑level algorithm (removeNode):

  1. Guard: ensure the node exists and is not an input or output (those are structural anchors).
  2. Ungate: detach connections gated BY the node (we don't currently reassign gater roles).
  3. Snapshot inbound / outbound connections (before mutation of adjacency lists).
  4. Disconnect all inbound, outbound, and self connections.
  5. Physically remove the node from the network's node array.
  6. Simple path repair heuristic: for every former inbound source and outbound target, add a direct connection if (a) both endpoints still exist, (b) they are distinct, and (c) no direct connection already exists. This keeps forward information flow possibilities.
  7. Mark topology / caches dirty so that subsequent activation / ordering passes rebuild state.

Notes / Limitations:

removeNode

removeNode(
  node: default,
): void

Remove a hidden node from the network while minimally repairing connectivity.

Parameters:

architecture/network/remove/network.remove.gates.utils.ts

clearConnectionGater

clearConnectionGater(
  candidateConnection: default,
): void

Clears gater reference so legacy checks treat connection as ungated.

Parameters:

Returns: Nothing.

detachGatesOwnedByNode

detachGatesOwnedByNode(
  removalContext: NodeRemovalContext,
): void

Removes gate records gated by target node and nulls their gater field.

Parameters:

Returns: Nothing.

isGatedByRemovedNode

isGatedByRemovedNode(
  candidateConnection: default,
  removedNode: default,
): boolean

Checks whether a gate candidate is currently gated by removed node.

Parameters:

Returns: True when removed node is gater.

keepGateConnectionAfterNodeRemoval

keepGateConnectionAfterNodeRemoval(
  candidateConnection: default,
  removedNode: default,
): boolean

Filters one gate connection while clearing removed-node gater ownership.

Parameters:

Returns: True when gate should remain in list.

architecture/network/remove/network.remove.finalize.utils.ts

markNetworkRemovalDirtyFlags

markNetworkRemovalDirtyFlags(
  internalNetwork: NetworkRemoveProps,
): void

Marks all cached removal-sensitive structures as dirty.

Parameters:

Returns: Nothing.

releaseRemovedNodeWhenPoolingEnabled

releaseRemovedNodeWhenPoolingEnabled(
  removedNode: default | undefined,
): void

Releases removed node to object pool when pooling is enabled.

Parameters:

Returns: Nothing.

removeNodeFromNetworkStorage

removeNodeFromNetworkStorage(
  removalContext: NodeRemovalContext,
): void

Removes node from network storage and conditionally releases it to pool.

Parameters:

Returns: Nothing.

spliceNodeFromNetwork

spliceNodeFromNetwork(
  removalContext: NodeRemovalContext,
): default | undefined

Splices node out of network list using validated index.

Parameters:

Returns: Removed node or undefined.

architecture/network/remove/network.remove.snapshot.utils.ts

cloneInboundConnections

cloneInboundConnections(
  targetNode: default,
): default[]

Clones inbound connections for safe traversal after mutation.

Parameters:

Returns: Inbound connection snapshot.

cloneOutboundConnections

cloneOutboundConnections(
  targetNode: default,
): default[]

Clones outbound connections for safe traversal after mutation.

Parameters:

Returns: Outbound connection snapshot.

countSelfConnections

countSelfConnections(
  targetNode: default,
): number

Counts self-loop connections currently attached to node.

Parameters:

Returns: Self-loop count.

createNodeConnectionSnapshot

createNodeConnectionSnapshot(
  removalContext: NodeRemovalContext,
): NodeConnectionSnapshotContext

Creates immutable snapshots of node adjacency lists before mutation.

Parameters:

Returns: Snapshot context.

disconnectAllNodeConnections

disconnectAllNodeConnections(
  removalContext: NodeRemovalContext,
  snapshotContext: NodeConnectionSnapshotContext,
): void

Disconnects all inbound, outbound, and self-loop edges for removed node.

Parameters:

Returns: Nothing.

disconnectConnectionGroup

disconnectConnectionGroup(
  network: default,
  connectionsToDisconnect: default[],
): void

Disconnects each connection in a single connection list.

Parameters:

Returns: Nothing.

disconnectSelfLoops

disconnectSelfLoops(
  network: default,
  targetNode: default,
  selfConnectionCount: number,
): void

Disconnects node self-loop connections using deterministic count traversal.

Parameters:

Returns: Nothing.

architecture/network/remove/network.remove.reconnect.utils.ts

collectReconnectEndpointPairs

collectReconnectEndpointPairs(
  snapshotContext: NodeConnectionSnapshotContext,
): ReconnectEndpointPairContext[]

Collects all valid source/target reconnect endpoint pairs.

Parameters:

Returns: Valid reconnect endpoint pairs.

connectPairWhenMissing

connectPairWhenMissing(
  network: default,
  reconnectPair: ReconnectEndpointPairContext,
): void

Connects one endpoint pair only when direct edge does not already exist.

Parameters:

Returns: Nothing.

createReconnectEndpointPair

createReconnectEndpointPair(
  inboundConnection: default,
  outboundConnection: default,
): ReconnectEndpointPairContext | undefined

Creates one reconnect endpoint pair when endpoints are valid.

Parameters:

Returns: Reconnect pair or undefined.

doesDirectConnectionExist

doesDirectConnectionExist(
  network: default,
  reconnectPair: ReconnectEndpointPairContext,
): boolean

Checks whether a direct connection already exists for reconnect pair.

Parameters:

Returns: True when direct edge already exists.

isReconnectPairValid

isReconnectPairValid(
  inboundConnection: default,
  outboundConnection: default,
): boolean

Validates reconnect pair endpoints.

Parameters:

Returns: True when reconnect pair should be attempted.

reconnectBridgedPaths

reconnectBridgedPaths(
  removalContext: NodeRemovalContext,
  snapshotContext: NodeConnectionSnapshotContext,
): void

Reconnects paths from former inbound sources to former outbound targets.

Parameters:

Returns: Nothing.

architecture/network/remove/network.remove.validation.utils.ts

createValidatedNodeRemovalContext

createValidatedNodeRemovalContext(
  network: default,
  targetNode: default,
): NodeRemovalContext

Creates validated immutable context for a node-removal operation.

Parameters:

Returns: Validated removal context.

ensureNodeIsNotStructuralAnchor

ensureNodeIsNotStructuralAnchor(
  targetNode: default,
): void

Ensures removal target is not an input/output anchor node.

Parameters:

Returns: Nothing.

isStructuralAnchorNode

isStructuralAnchorNode(
  targetNode: default,
): boolean

Checks whether node is an input/output structural anchor.

Parameters:

Returns: True when node is an anchor.

resolveNodeIndexOrThrow

resolveNodeIndexOrThrow(
  network: default,
  targetNode: default,
): number

Resolves node index and throws when missing.

Parameters:

Returns: Node index inside network list.

Generated from source JSDoc • GitHub