Skip to main content

god_gragh/
lib.rs

1//! # God-Graph: 高性能 Rust 图操作库
2//!
3//! God-Graph 是一个设计用于高性能计算的图数据结构和算法库,
4//! 采用 CSR 格式、Arena 分配器和并行计算优化。
5//!
6//! ## 特性
7//!
8//! - **高性能内存布局**: CSR (Compressed Sparse Row) 格式,cache-friendly
9//! - **稳定索引**: Arena 分配器 + generation 计数,防止 ABA 问题
10//! - **并行算法**: 基于 rayon 的并行 BFS、PageRank 等算法
11//! - **泛型支持**: 节点和边支持任意数据类型
12//!
13//! ## 快速开始
14//!
15//! ```
16//! use god_gragh::prelude::*;
17//!
18//! // 创建有向图
19//! let mut graph = Graph::<String, f64>::directed();
20//!
21//! // 添加节点
22//! let a = graph.add_node("A".to_string()).unwrap();
23//! let b = graph.add_node("B".to_string()).unwrap();
24//! let c = graph.add_node("C".to_string()).unwrap();
25//!
26//! // 添加边
27//! graph.add_edge(a, b, 1.0).unwrap();
28//! graph.add_edge(b, c, 2.0).unwrap();
29//! graph.add_edge(a, c, 4.0).unwrap();
30//!
31//! // 遍历邻居
32//! for neighbor in graph.neighbors(a) {
33//!     println!("Neighbor: {}", graph[neighbor]);
34//! }
35//! ```
36//!
37//! ## 并行算法(需要 `parallel` 特性)
38//!
39//! ```no_run
40//! # #[cfg(feature = "parallel")]
41//! # {
42//! use god_gragh::prelude::*;
43//! use god_gragh::algorithms::parallel::par_pagerank;
44//!
45//! let mut graph = Graph::<i32, f64>::undirected();
46//! // 使用并行 PageRank
47//! let ranks = par_pagerank(&graph, 0.85, 20);
48//! # }
49//! ```
50
51#![cfg_attr(not(feature = "std"), no_std)]
52#![warn(missing_docs)]
53#![warn(rustdoc::missing_crate_level_docs)]
54
55#[cfg(not(feature = "std"))]
56extern crate alloc;
57
58pub mod errors;
59pub mod graph;
60pub mod node;
61pub mod edge;
62pub mod algorithms;
63pub mod generators;
64pub mod export;
65pub mod utils;
66pub mod prelude;
67pub mod tensor;
68
69// 重新导出核心类型
70pub use errors::{GraphError, GraphResult};
71pub use graph::Graph;
72pub use node::{NodeIndex, NodeRef};
73pub use edge::{EdgeIndex, EdgeRef};
74
75/// 库版本号
76pub const VERSION: &str = env!("CARGO_PKG_VERSION");
77
78/// 最大支持的节点数量
79pub const MAX_NODES: usize = usize::MAX >> 1;
80
81/// 最大支持的边数量
82pub const MAX_EDGES: usize = usize::MAX >> 1;