Skip to content

Commit

Permalink
sort output from iterating over table
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Oct 8, 2024
1 parent b3a5416 commit 1c6ea0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum MergeFn {
}

/// All information we know determined by the input.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct TupleOutput {
pub value: Value,
pub timestamp: u32,
Expand Down
15 changes: 9 additions & 6 deletions src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ordered_float::NotNan;
use std::collections::VecDeque;
use symbol_table::GlobalSymbol;

use crate::{ast::ResolvedFunctionDecl, util::HashMap, EGraph, TupleOutput, Value};
use crate::{ast::ResolvedFunctionDecl, EGraph, IndexMap, TupleOutput, Value};

pub struct SerializeConfig {
// Maximumum number of functions to include in the serialized graph, any after this will be discarded
Expand Down Expand Up @@ -95,7 +95,7 @@ impl EGraph {
.iter()
.filter(|(_, function)| !function.decl.ignore_viz)
.map(|(name, function)| {
function
let mut res = function
.nodes
.iter_range(0..function.nodes.num_offsets(), true)
.take(config.max_calls_per_function.unwrap_or(usize::MAX))
Expand All @@ -111,7 +111,10 @@ impl EGraph {
}),
)
})
.collect::<Vec<_>>()
.collect::<Vec<_>>();
// this is an expensive sort, but necessary to make the output deterministic
res.sort_by_key(|val| (val.0.name, val.1, val.2, val.3.clone(), val.4.clone()));
res
})
// Filter out functions with no calls
.filter(|f| !f.is_empty())
Expand All @@ -124,15 +127,15 @@ impl EGraph {
// This is for when we need to find what node ID to use for an edge to an e-class, we can rotate them evenly
// amoung all possible options.
let mut node_ids: NodeIDs = all_calls.iter().fold(
HashMap::default(),
IndexMap::default(),
|mut acc, (_decl, _input, output, class_id, node_id)| {
if self
.get_sort_from_value(&output.value)
.unwrap()
.is_eq_sort()
{
acc.entry(class_id.clone())
.or_insert_with(VecDeque::new)
.or_default()
.push_back(node_id.clone());
}
acc
Expand Down Expand Up @@ -310,4 +313,4 @@ impl EGraph {
}
}

type NodeIDs = HashMap<egraph_serialize::ClassId, VecDeque<egraph_serialize::NodeId>>;
type NodeIDs = IndexMap<egraph_serialize::ClassId, VecDeque<egraph_serialize::NodeId>>;

0 comments on commit 1c6ea0f

Please sign in to comment.