1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! # hypergraph-rs
//!
//! A hypergraph library for Rust. A hypergraph is a graph whose edges can join any number
//! of nodes, not just two. This crate is a port of [XGI](https://github.com/xgi-org/xgi),
//! the Python hypergraph library, and it builds on
//! [rustworkx-core](https://crates.io/crates/rustworkx-core). Node and edge ids are strings,
//! and every listing keeps the order in which things were added.
//!
//! Add it with `cargo add hypergraph-rs`.
//!
//! ## Quick start
//!
//! ```
//! use hypergraph_rs::algorithms::connected::number_connected_components;
//! use hypergraph_rs::Hypergraph;
//!
//! // Nodes, edges and memberships carry no value here, so all three types are `()`.
//! let mut h: Hypergraph<(), (), ()> = Hypergraph::new();
//!
//! // An edge joins any number of nodes. Nodes that do not exist yet are created.
//! h.add_edge(
//! vec!["ana".into(), "bo".into(), "cy".into()],
//! Some("club".into()),
//! (),
//! )
//! .unwrap();
//! h.add_edge(
//! vec!["bo".into(), "cy".into(), "di".into(), "ed".into()],
//! Some("choir".into()),
//! (),
//! )
//! .unwrap();
//! h.add_edge(vec!["fay".into(), "gus".into()], Some("pair".into()), ())
//! .unwrap();
//!
//! // Listings keep the order in which things were added.
//! assert_eq!(h.node_ids(), ["ana", "bo", "cy", "di", "ed", "fay", "gus"]);
//! assert_eq!(h.members("choir").unwrap(), ["bo", "cy", "di", "ed"]);
//! assert_eq!(h.memberships("bo").unwrap(), ["club", "choir"]);
//!
//! // One statistic: "pair" shares no member with the other two edges, so there are
//! // two connected components.
//! assert_eq!(number_connected_components(&h), 2);
//! ```
//!
//! ## What is in it
//!
//! - [`Hypergraph`]: undirected edges. [`DiHypergraph`]: each edge has a tail and a head.
//! [`SimplicialComplex`]: a hypergraph that keeps every subface of each simplex.
//! - A hypergraph has three type parameters: the value on a node, on an edge and on a
//! membership. Each defaults to a JSON value. The statistics, readers, writers and
//! conversions work on that default type.
//! - Modules, switched by the feature flags below: [`algorithms`], `generators`, `stats`,
//! `readwrite`, `layout`, `viz`, `raster`, `geometry`, `convert`, `dynamics`, `communities`. The
//! modules [`core`], [`linalg`] and [`utils`] are always there.
//!
//! ## A value on a membership
//!
//! A membership is the fact that one node belongs to one edge. XGI has no value on a
//! membership. The membership value is this crate's own addition: the third type parameter,
//! read and written with `member_data`, `set_member_data`, `members_with_data` and
//! `add_node_to_edge_with_data` (on [`DiHypergraph`], `member_data`, `set_member_data` and
//! `add_node_to_edge_with_data` also take the role, and `dimembers_with_data` lists the tail
//! and the head together). A new membership carries `M::default()`. The XGI-compatible
//! formats, the Python package and the WASM bindings do not carry the value.
//!
//! ```
//! use hypergraph_rs::Hypergraph;
//!
//! let mut h: Hypergraph<(), (), u64> = Hypergraph::new();
//! h.add_node_to_edge_with_data("council", "teachers", 3).unwrap();
//! h.add_node_to_edge_with_data("union", "teachers", 40).unwrap();
//! assert_eq!(h.member_data("council", "teachers"), Some(&3));
//! assert_eq!(h.member_data("union", "teachers"), Some(&40));
//! ```
//!
//! ## Feature flags
//!
//! The default features are `algorithms`, `generators`, `stats`, `readwrite`, `layout`,
//! `viz`, `raster` and `geometry`.
//!
//! | Feature | Turns on |
//! | --- | --- |
//! | `algorithms` | connected components, shortest paths, clustering, centrality, assortativity, simpliciality |
//! | `generators` | classic, random, lattice, uniform and simplicial generators (seeded) |
//! | `stats` | node and edge statistics, for the default type of hypergraph |
//! | `readwrite` | edge list, bipartite edge list, JSON, HIF and incidence matrix readers and writers, and a BiGG dictionary reader |
//! | `layout` | deterministic layouts: node positions and the shape drawn for each edge |
//! | `viz` | a scene graph built from a layout, with JSON and SVG output (needs `layout`) |
//! | `raster` | the base of the terminal-text rasterizer (needs `viz` and `algorithms`) |
//! | `dynamics` | Kuramoto synchronization |
//! | `communities` | spectral clustering |
//! | `convert` | conversions between hypergraphs and edge lists, dictionaries and graphs |
//! | `network` | declares `readwrite::bigg::load_bigg_data`, which is not implemented and always returns an error |
//! | `cells3d` | hexagonal-cell scenes and instruments for the rasterizer (needs `raster`, `communities` and the `h3o` crate) |
//! | `raster-png` | PNG output for the rasterizer (needs `cells3d` and the `png` crate) |
//! | `geometry` | outlines of a weighted set (ring, capsule, membrane), placement at a weighted mix of fixed points, spreading in fixed steps; the same bits on every machine |
//! | `all` | every feature above |
//!
//! Every feature builds on its own, without the defaults.
//!
//! ## Minimum Rust version
//!
//! Rust 1.90, for the workspace and for every feature of this crate.
// docs.rs builds with `--cfg docsrs` on nightly; `doc_cfg` labels each item with its feature.
pub use DiHypergraph;
pub use ;
pub use subhypergraph;
pub use ;
pub use ;
pub use ;
pub use ;