#![cfg_attr(coverage_nightly, coverage(off))]
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use trueno_graph::{CsrGraph, NodeId as TruenoNodeId};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeData {
pub path: PathBuf,
pub module: String,
pub symbols: Vec<Symbol>,
pub loc: usize,
pub complexity: f64,
pub ast_hash: u64, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Symbol {
pub name: String,
pub kind: SymbolKind,
pub visibility: Visibility,
pub line: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum SymbolKind {
Function,
Struct,
Enum,
Trait,
Module,
Variable,
Constant,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd)]
pub enum Visibility {
Private,
Protected,
Public,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EdgeData {
Import {
weight: f64,
visibility: Visibility,
},
FunctionCall {
count: usize,
async_call: bool,
},
TypeDependency {
strength: f64,
kind: TypeKind,
},
DataFlow {
confidence: f64,
direction: FlowDirection,
},
Inheritance {
depth: usize,
},
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum TypeKind {
Generic,
Trait,
Struct,
Enum,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum FlowDirection {
Forward,
Backward,
Bidirectional,
}
pub type NodeId = TruenoNodeId;
#[derive(Debug, Clone)]
pub struct DependencyGraph {
graph: CsrGraph,
node_data: HashMap<NodeId, NodeData>,
edge_data: HashMap<(NodeId, NodeId), EdgeData>,
next_id: u32,
}
#[derive(Debug, Clone, Copy)]
pub struct EdgeRef<'a> {
source: NodeId,
target: NodeId,
weight: &'a EdgeData,
}
#[derive(Debug, Clone)]
pub struct UndirectedGraph {
graph: CsrGraph,
node_data: HashMap<NodeId, NodeData>,
edge_weights: HashMap<(NodeId, NodeId), f64>,
next_id: u32,
}
#[derive(Debug, Clone, Copy)]
pub struct UndirectedEdgeRef<'a> {
source: NodeId,
target: NodeId,
weight: f64,
_phantom: std::marker::PhantomData<&'a ()>,
}
#[derive(Debug, Clone, Default)]
pub struct SimpleSparseMatrix {
pub nrows: usize,
pub ncols: usize,
pub triplets: Vec<(usize, usize, f64)>,
}
#[derive(Debug, Clone)]
pub struct GraphMatrices {
pub adjacency: SimpleSparseMatrix,
pub transition: SimpleSparseMatrix,
pub laplacian: SimpleSparseMatrix,
pub out_degrees: Vec<f64>,
pub node_count: usize,
pub edges: Vec<(usize, usize, f64)>,
}
include!("types_dependency_graph.rs");
include!("types_undirected_graph.rs");
include!("types_matrices.rs");
include!("types_tests.rs");