Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorts/types/names to classes #1

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ pub struct EGraph {
pub nodes: IndexMap<NodeId, Node>,
#[cfg_attr(feature = "serde", serde(default))]
pub root_eclasses: Vec<ClassId>,
// Optional mapping of e-class ids to some additional data about the e-class
#[cfg_attr(feature = "serde", serde(default))]
pub class_data: IndexMap<ClassId, ClassData>,
#[cfg_attr(feature = "serde", serde(skip))]
once_cell_classes: OnceCell<IndexMap<ClassId, Class>>,
}
Expand Down Expand Up @@ -180,3 +183,10 @@ pub struct Class {
pub id: ClassId,
pub nodes: Vec<NodeId>,
}

#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct ClassData {
#[cfg_attr(feature = "serde", serde(rename = "type"))]
pub typ: Option<String>,
}
2 changes: 1 addition & 1 deletion tests/round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use egraph_serialize::*;
#[test]
fn test_round_trip() {
let mut n_tested = 0;
let pattern = "../extraction-gym/data/**/*.json";
let pattern = "tests/*.json";
for entry in glob::glob(pattern).expect("Failed to read glob pattern") {
let entry = entry.unwrap();
println!("Testing {:?}", entry);
Expand Down
5 changes: 5 additions & 0 deletions tests/tiny.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
"eclass": "12",
"cost": 6.0
}
},
"class_data": {
"18": {
"type": "foobar"
}
}
}