diff --git a/src/lib.rs b/src/lib.rs index 42d9e67..3af0741 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ /// position, index, or key to a hashmap. It should allow O(1) access to the Node. pub trait GraphLike { fn get_node(&self, id: NodeId) -> Option<&Node>; + fn set_node(&mut self, id: NodeId, node: Node); fn iter_ids(&self) -> impl Iterator; fn iter_neighbor_ids(&self, id: NodeId) -> impl Iterator; @@ -21,23 +22,26 @@ pub trait GraphLike { /// TODO: Replace return type with a result that explains the reason for failure. This could /// help with rollback to recover from impossible generation - fn collapse_one(&mut self, rules: &impl Ruleset) -> Option where NodeId: Copy, Self: Sized { + fn single_step(&mut self, rules: &impl Ruleset) -> Option where NodeId: Copy, Self: Sized { let id = rules.find_lowest_entropy(self)?; - rules.choose(self, id); + let node = rules.choose(self, id).expect("Ruleset::choose should also return Some if Ruleset::entropy returns Some"); + let empty_ids = self.iter_empty(); + None } } pub trait Ruleset { fn entropy(&self, graph: &impl GraphLike, id: NodeId) -> Option where NodeId: Copy; - fn choose(&self, graph: &impl GraphLike, id: NodeId) -> Node where NodeId: Copy; + fn choose(&self, graph: &impl GraphLike, id: NodeId) -> Option where NodeId: Copy; fn find_lowest_entropy(&self, graph: &impl GraphLike) -> Option where NodeId: Copy { graph.iter_empty() .map(|id| (id, self.entropy(graph, id))) - // Option apparently implements PartialOrd + // NOTE: Option implements PartialOrd // None is considered smaller than any Some value // This works out, since we want to find impossible nodes (entropy returns None) + // But make sure this doesn't cause unexpected behavior later on .min_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) .map(|(id, _)| id) }