From 4d75a0bf97fe30b8ebaa1809b8e66fa6a4eec389 Mon Sep 17 00:00:00 2001 From: hheik <4469778+hheik@users.noreply.github.com> Date: Fri, 24 Apr 2026 18:25:30 +0300 Subject: [PATCH] Small changes --- src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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) }