1use serde::{Deserialize, Serialize};
22use std::collections::HashMap;
23use std::fmt;
24
25mod inconsistencies;
26mod inspect;
27mod merge;
28mod ops;
29mod parse;
30mod serialization;
31mod slice;
32mod xml;
33
34#[derive(Clone, Serialize, Deserialize, Eq, PartialOrd, PartialEq, Ord)]
35struct Edge {
36 to: u32,
37 a: String,
38}
39
40impl Edge {
41 fn new(to: u32, a: String) -> Edge {
42 Edge { to, a }
43 }
44}
45
46#[derive(Clone, Serialize, Deserialize)]
47struct Vertex {
48 edges: Vec<Edge>,
49 data: Vec<u8>,
50}
51
52impl Vertex {
53 pub fn empty() -> Self {
55 Vertex {
56 edges: vec![],
57 data: vec![],
58 }
59 }
60}
61
62#[derive(Serialize, Deserialize)]
63pub struct Sot {
64 vertices: HashMap<u32, Vertex>,
65}
66
67impl fmt::Debug for Sot {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69 let mut lines = vec![];
70 for (i, v) in self.vertices.iter() {
71 let mut attrs = v
72 .edges
73 .iter()
74 .map(|e| format!("\n\t{} ➞ ν{}", e.a, e.to))
75 .collect::<Vec<String>>();
76 if !&v.data.is_empty() {
77 attrs.push(format!("{}b", v.data.len()));
78 }
79 lines.push(format!("ν{} -> ⟦{}⟧", i, attrs.join(", ")));
80 }
81 f.write_str(lines.join("\n").as_str())
82 }
83}
84
85impl Sot {
86 pub fn empty() -> Self {
88 Sot {
89 vertices: HashMap::new(),
90 }
91 }
92
93 pub fn max(&self) -> u32 {
95 let mut id = 0;
96 for v in self.vertices.keys() {
97 if *v > id {
98 id = *v;
99 }
100 }
101 id
102 }
103}
104
105#[cfg(test)]
106use anyhow::Result;
107
108#[test]
109fn makes_an_empty_sot() -> Result<()> {
110 let mut sot = Sot::empty();
111 sot.add(0)?;
112 assert_eq!(1, sot.vertices.len());
113 Ok(())
114}
115
116#[test]
117fn calculates_max() -> Result<()> {
118 let mut sot = Sot::empty();
119 sot.add(0)?;
120 sot.add(1)?;
121 assert_eq!(1, sot.max());
122 Ok(())
123}