pub struct Graph { /* private fields */ }Implementations§
Source§impl Graph
impl Graph
pub fn new(mode: CompatibilityMode) -> Self
pub fn with_runtime_policy(runtime_policy: RuntimePolicy) -> Self
pub fn strict() -> Self
pub fn complete_graph(mode: CompatibilityMode, n: usize) -> Self
Sourcepub fn grid_2d(mode: CompatibilityMode, m: usize, n: usize) -> Self
pub fn grid_2d(mode: CompatibilityMode, m: usize, n: usize) -> Self
Build a non-periodic 2-D grid with NetworkX’s node and edge insertion sequence. Canonical node keys are row-major all-int tuple strings like “(i, j)”.
Sourcepub fn grid_nd(
mode: CompatibilityMode,
dimensions: &[usize],
periodic: &[bool],
) -> Result<Self, GraphError>
pub fn grid_nd( mode: CompatibilityMode, dimensions: &[usize], periodic: &[bool], ) -> Result<Self, GraphError>
Build NetworkX’s n-dimensional integer grid graph in one bulk pass.
NetworkX constructs this as repeated cartesian products of path/cycle graphs, then flattens the nested tuple labels. The product order matters: periodic axes use cycle edge-view order, not a simple coordinate loop.
Sourcepub fn kneser(mode: CompatibilityMode, n: usize, k: usize) -> Self
pub fn kneser(mode: CompatibilityMode, n: usize, k: usize) -> Self
br-r37-c1-z2eaa: Kneser graph K(n, k) replicating NetworkX’s exact
construction sequence. Nodes are k-subsets of 0..n as all-int-tuple
canonicals “(a, b, …)” (br-r37-c1-y7m24). nx builds via
add_edges_from((s, t) for s in subsets for t in combinations(universe - set(s), k)) — node order is edge-DISCOVERY
order (u then v per new edge) and each unordered edge is offered
twice (the second add is a structural no-op). The complement
universe - set(s) iterates ASCENDING whenever every value fits its
exact CPython set slot — the Python wrapper gates this kernel on
that condition, so lexicographic combinations over the sorted
complement reproduce nx byte-for-byte. For 2k > n nodes are
pre-added in subset order and no edges exist.
pub fn hardened() -> Self
pub fn mode(&self) -> CompatibilityMode
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
pub fn revision(&self) -> u64
pub fn has_node(&self, node: &str) -> bool
pub fn has_edge(&self, left: &str, right: &str) -> bool
pub fn nodes_ordered(&self) -> Vec<&str>
pub fn get_node_index(&self, node: &str) -> Option<usize>
pub fn get_node_name(&self, index: usize) -> Option<&str>
pub fn neighbors(&self, node: &str) -> Option<Vec<&str>>
pub fn neighbors_iter( &self, node: &str, ) -> Option<impl Iterator<Item = &str> + '_>
Sourcepub fn neighbors_indices(&self, node_idx: usize) -> Option<&[usize]>
pub fn neighbors_indices(&self, node_idx: usize) -> Option<&[usize]>
Return neighbor indices for O(1) traversal. Avoids string hashing during BFS/DFS. Returns None if node index is out of bounds.
Sourcepub fn clone_with_fresh_policy(&self) -> Self
pub fn clone_with_fresh_policy(&self) -> Self
br-r37-c1-7dpyg: structural clone with a FRESH RuntimePolicy —
Clone deep-copies the unbounded decision ledger (copy() measured
2.3-2.8x slower on per-edge-ctor sources with identical structure);
result graphs carry the MODE, not the history.
Sourcepub fn apply_row_orders(&mut self, orders: &[(String, Vec<String>)])
pub fn apply_row_orders(&mut self, orders: &[(String, Vec<String>)])
br-r37-c1-u3qyn: restore explicit adjacency row orders (pickle
round-trip). Each entry is (node, neighbor order); rows are
rebuilt in the given order with any unlisted survivors appended
in their current order (robust to stale state). The integer
adj_indices mirror is rebuilt to match.
Sourcepub fn reorder_rows_for_nx_copy_walk(&mut self)
pub fn reorder_rows_for_nx_copy_walk(&mut self)
br-r37-c1-0ek49: reorder every adjacency row into NetworkX’s
Graph.copy() walk order. nx copy rebuilds via
add_edges_from((u, v, d) for u in _adj for v in _adj[u]), so an
unordered pair enters BOTH endpoint rows at its first touch —
during the earlier endpoint’s row scan. Row u therefore lists
neighbors at a smaller node position first (ordered by that
neighbor’s scan time: (pos(v), index of u within row v)),
followed by its remaining neighbors — self-loops included — in
row u’s original order. Call on a fresh clone inside copy-shaped
constructors; graph content is unchanged, only row order moves.
pub fn edges_storage_order_index_iter( &self, ) -> impl Iterator<Item = (usize, usize, &AttrMap)> + '_
pub fn neighbor_count(&self, node: &str) -> usize
Sourcepub fn degree(&self, node: &str) -> usize
pub fn degree(&self, node: &str) -> usize
Return the degree of a node. Self-loops contribute 2 to the degree (NetworkX convention).
Sourcepub fn degree_by_index(&self, idx: usize) -> usize
pub fn degree_by_index(&self, idx: usize) -> usize
br-r37-c1-degidx: degree by node INDEX — O(1), zero String hashing (the &str path costs 2 hashes/node: neighbor_count’s get_index_of + the self-loop has_edge). Used by the DegreeView iterator which already walks nodes in index order.
pub fn node_attrs(&self, node: &str) -> Option<&AttrMap>
pub fn edge_attrs(&self, left: &str, right: &str) -> Option<&AttrMap>
Sourcepub fn edge_attrs_by_indices(
&self,
left_idx: usize,
right_idx: usize,
) -> Option<&AttrMap>
pub fn edge_attrs_by_indices( &self, left_idx: usize, right_idx: usize, ) -> Option<&AttrMap>
br-r37-c1-d58s8: index-keyed attr access — a DIRECT map get for callers that already hold node indices (kernels, CSR weight builders, compose walks). Zero node-map probes.
pub fn nodes_are_contiguous_int_prefix(&self) -> bool
pub fn evidence_ledger(&self) -> &EvidenceLedger
pub fn runtime_policy(&self) -> &RuntimePolicy
pub fn set_runtime_policy(&mut self, runtime_policy: RuntimePolicy)
Sourcepub fn is_directed(&self) -> bool
pub fn is_directed(&self) -> bool
Type identity: always false for undirected Graph.
Sourcepub fn is_multigraph(&self) -> bool
pub fn is_multigraph(&self) -> bool
Type identity: always false for Graph (not a multigraph).
pub fn add_node(&mut self, node: impl Into<String>) -> bool
pub fn add_node_with_attrs( &mut self, node: impl Into<String>, attrs: AttrMap, ) -> bool
Sourcepub fn extend_nodes_unrecorded<I, N>(&mut self, nodes: I) -> usize
pub fn extend_nodes_unrecorded<I, N>(&mut self, nodes: I) -> usize
Bulk node insertion for generated/batched construction paths where per-node compatibility evidence would be pure constant-factor overhead.
Sourcepub fn extend_nodes_with_attrs_unrecorded<I>(&mut self, nodes: I) -> usize
pub fn extend_nodes_with_attrs_unrecorded<I>(&mut self, nodes: I) -> usize
br-r37-c1-l5ve7: bulk node insert WITH attrs, one ledger record — mirror of DiGraph::extend_nodes_with_attrs_unrecorded. Existing nodes merge attrs (extend), matching add_node_with_attrs.
pub fn apply_node_defaults(&mut self, defaults: &AttrMap) -> bool
pub fn add_edge( &mut self, left: impl Into<String>, right: impl Into<String>, ) -> Result<(), GraphError>
Sourcepub fn extend_edges_unrecorded<I, L, R>(&mut self, edges: I) -> usize
pub fn extend_edges_unrecorded<I, L, R>(&mut self, edges: I) -> usize
Bulk-add a sequence of attribute-free edges. Bypasses the
per-edge runtime_policy.record_decision call that
[add_edge_with_attrs] makes. Instead, emit one summary record
for the whole batch.
Intended for fnx-internal callers that build a fresh graph
from a known-good edge list (e.g., complement,
transitive_closure, etc.) where the per-edge
incompatibility-probability accounting would just add
constant-factor overhead and is uninteresting for the policy
log.
Nodes referenced by edges are auto-created if absent
(matching add_edge semantics). br-r37-c1-4jd8m.
Sourcepub fn extend_existing_index_edges_unrecorded<I>(&mut self, edges: I) -> usize
pub fn extend_existing_index_edges_unrecorded<I>(&mut self, edges: I) -> usize
Bulk-add attribute-free edges whose endpoints have already been
resolved to existing node indices. This is the index-space sibling of
[extend_edges_unrecorded]: it preserves duplicate handling, adjacency
row order, edge storage order, and string-canonical endpoint orientation
without per-edge node-name allocation or map lookup.
Sourcepub fn extend_existing_index_edges_with_attrs_unrecorded<I>(
&mut self,
edges: I,
) -> usize
pub fn extend_existing_index_edges_with_attrs_unrecorded<I>( &mut self, edges: I, ) -> usize
br-r37-c1-dodattrbatch: bulk-add ATTRIBUTED edges by EXISTING node index
— the attributed sibling of [extend_existing_index_edges_unrecorded].
All endpoints MUST already exist (callers gate on a contiguous-int node
prefix). A new edge takes the given AttrMap; a duplicate edge MERGES
(last-writer-wins per key) exactly like add_edge_with_attrs. Replaces
the per-edge ledger with one batch summary; no String hashing for the
endpoints (they arrive as integer indices).
Sourcepub fn extend_edges_with_attrs_unrecorded<I>(&mut self, edges: I) -> usize
pub fn extend_edges_with_attrs_unrecorded<I>(&mut self, edges: I) -> usize
br-r37-c1-pr8q6: bulk-add ATTRIBUTED edges without per-edge ledger
records — the attributed sibling of [extend_edges_unrecorded].
Semantics match a sequence of add_edge_with_attrs calls exactly:
nodes auto-created in first-appearance order, duplicate edges MERGE
their attrs into the existing map (extend), adjacency /
adj_indices / edge_index_endpoints maintained identically. Only
the per-edge record_decision push (timestamp + String allocs per
edge, the dominant cost of attributed bulk construction) is replaced
by one batch summary record.
Callers MUST pre-screen attr keys starting with
"__fnx_incompatible" and route those edges through
add_edge_with_attrs, which owns the FailClosed contract for them.
Sourcepub fn extend_fresh_index_edges_with_attrs_unrecorded<I, N>(
&mut self,
nodes: N,
edges: I,
) -> usize
pub fn extend_fresh_index_edges_with_attrs_unrecorded<I, N>( &mut self, nodes: N, edges: I, ) -> usize
Bulk-add attributed undirected edges into a fresh graph when the caller has already assigned NetworkX-compatible node indices in first-seen order.
This is the fresh/indexed sibling of
[extend_edges_with_attrs_unrecorded]. It preserves duplicate
insert-or-merge semantics, adjacency row order, self-loop handling, and
the public edges() orientation rule used by the string-key path.
pub fn add_edge_with_attrs( &mut self, left: impl Into<String>, right: impl Into<String>, attrs: AttrMap, ) -> Result<(), GraphError>
pub fn apply_edge_defaults(&mut self, defaults: &AttrMap) -> bool
Sourcepub fn replace_edge_attrs(
&mut self,
left: &str,
right: &str,
attrs: AttrMap,
) -> bool
pub fn replace_edge_attrs( &mut self, left: &str, right: &str, attrs: AttrMap, ) -> bool
br-r37-c1-sjf4t: overwrite the attribute map for an existing edge,
matching post-creation Python-side mutations. Unlike
add_edge_with_attrs which extends, this replaces. Returns
true if the edge existed and was updated, false otherwise.
Sourcepub fn replace_node_attrs(&mut self, node: &str, attrs: AttrMap) -> bool
pub fn replace_node_attrs(&mut self, node: &str, attrs: AttrMap) -> bool
br-r37-c1-sjf4t: overwrite the attribute map for an existing node.
pub fn remove_edge(&mut self, left: &str, right: &str) -> bool
pub fn remove_node(&mut self, node: &str) -> bool
pub fn remove_nodes_from<'a, I>(&mut self, nodes: I) -> (usize, usize)where
I: IntoIterator<Item = &'a str>,
Sourcepub fn edge_weights_all_int(&self, attr: &str) -> bool
pub fn edge_weights_all_int(&self, attr: &str) -> bool
Rebuild integer adjacency from string adjacency. Called after node
removal since indices shift.
br-r37-c1-d58s8: revision-keyed memo of “every edge’s attr
value is an integer (missing = default 1 = int)”.
pub fn edges_ordered(&self) -> Vec<EdgeSnapshot>
pub fn edges_ordered_borrowed(&self) -> Vec<(&str, &str, &AttrMap)>
Sourcepub fn edges_ordered_indices(&self) -> Vec<(usize, usize)>
pub fn edges_ordered_indices(&self) -> Vec<(usize, usize)>
br-r37-c1-2a00r: index-space twin of edges_ordered_borrowed — yields
(u, v) node indices in the SAME node-major traversed order/orientation,
without resolving endpoints to &str. Lets the EdgeView iterate edges and
look up the per-index Python node-key object directly (O(1) incref) instead
of hashing the canonical String per endpoint via py_node_key.