Skip to content

Commit

Permalink
Clean the node ports builder
Browse files Browse the repository at this point in the history
  • Loading branch information
arnodb committed Nov 17, 2024
1 parent e42ba5c commit 80e221a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 87 deletions.
13 changes: 7 additions & 6 deletions examples/quirky_binder_example_index_first_char/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ use quirky_binder::{
use super::tokenize;
#(
name: "quirky_binder_monitor",
feature: "quirky_binder_monitor",
)
{ ( quirky_binder::filter::monitor::monitor() ) }
{
(
function_produce#read_input(
Expand Down Expand Up @@ -155,6 +149,13 @@ use super::tokenize;
)
)
}
#(
name: "quirky_binder_monitor",
feature: "quirky_binder_monitor",
)
{ ( quirky_binder::filter::monitor::monitor() ) }
"###
));

Expand Down
13 changes: 7 additions & 6 deletions examples/quirky_binder_example_tree/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ use quirky_binder::{
},
};
#(
name: "quirky_binder_monitor",
feature: "quirky_binder_monitor",
)
{ ( quirky_binder::filter::monitor::monitor() ) }
{
(
function_produce#read_fs(
Expand Down Expand Up @@ -99,6 +93,13 @@ use quirky_binder::{
-> children
)
}
#(
name: "quirky_binder_monitor",
feature: "quirky_binder_monitor",
)
{ ( quirky_binder::filter::monitor::monitor() ) }
"###
));

Expand Down
13 changes: 7 additions & 6 deletions examples/quirky_binder_example_wordlist/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ use quirky_binder::{
},
};
#(
name: "quirky_binder_monitor",
feature: "quirky_binder_monitor",
)
{ ( quirky_binder::filter::monitor::monitor() ) }
{
(
function_produce#read_token(
Expand Down Expand Up @@ -137,6 +131,13 @@ use quirky_binder::{
)
)
}
#(
name: "quirky_binder_monitor",
feature: "quirky_binder_monitor",
)
{ ( quirky_binder::filter::monitor::monitor() ) }
"###
));

Expand Down
61 changes: 32 additions & 29 deletions quirky_binder/src/drawing/graph/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ impl<'a, PortKey: Ord + Copy + Debug, PathKey: Ord + Copy + Debug>
color,
});
}

pub fn node_ports_builder(&mut self) -> NodePortsBuilder<'a, '_, PortKey, PathKey> {
NodePortsBuilder::new(self)
}
}

#[allow(clippy::from_over_into)]
Expand Down Expand Up @@ -201,15 +197,22 @@ enum NodePortColumn<PortKey, PathKey> {
None,
}

#[derive(new)]
pub struct NodePortsBuilder<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Ord + Copy + Debug> {
helper: &'h mut DrawingHelper<'a, PortKey, PathKey>,
#[new(default)]
pub struct NodePortsBuilder<PortKey: Ord + Copy + Debug, PathKey: Ord + Copy + Debug> {
columns: Vec<NodePortColumn<PortKey, PathKey>>,
}

impl<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
NodePortsBuilder<'a, 'h, PortKey, PathKey>
impl<PortKey: Ord + Copy + Debug, PathKey: Ord + Copy + Debug> Default
for NodePortsBuilder<PortKey, PathKey>
{
fn default() -> Self {
NodePortsBuilder {
columns: Default::default(),
}
}
}

impl<PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
NodePortsBuilder<PortKey, PathKey>
{
pub fn input(
&mut self,
Expand Down Expand Up @@ -446,7 +449,10 @@ impl<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
}
}

pub fn build(mut self) -> Vec<DrawingPortsColumn> {
pub fn build(
mut self,
helper: &mut DrawingHelper<PortKey, PathKey>,
) -> Vec<DrawingPortsColumn> {
self.consolidate();
self.columns
.into_iter()
Expand All @@ -456,9 +462,9 @@ impl<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
port_size,
edge_tail,
} => {
let port_id = DrawingPortId::from(self.helper.port_count);
self.helper.port_count += 1;
self.helper.push_edge(&edge_tail, port_id, path);
let port_id = DrawingPortId::from(helper.port_count);
helper.port_count += 1;
helper.push_edge(&edge_tail, port_id, path);
Some(DrawingPortsColumn {
ports: vec![DrawingPort {
id: port_id,
Expand All @@ -472,9 +478,9 @@ impl<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
path: _,
port_size,
} => {
let port_id = DrawingPortId::from(self.helper.port_count);
self.helper.port_count += 1;
let old = self.helper.output_ports.insert(port_key, port_id);
let port_id = DrawingPortId::from(helper.port_count);
helper.port_count += 1;
let old = helper.output_ports.insert(port_key, port_id);
assert!(old.is_none());
Some(DrawingPortsColumn {
ports: vec![DrawingPort {
Expand All @@ -490,10 +496,10 @@ impl<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
edge_tail,
output_port_key,
} => {
let port_id = DrawingPortId::from(self.helper.port_count);
self.helper.port_count += 1;
self.helper.push_edge(&edge_tail, port_id, path);
let old = self.helper.output_ports.insert(output_port_key, port_id);
let port_id = DrawingPortId::from(helper.port_count);
helper.port_count += 1;
helper.push_edge(&edge_tail, port_id, path);
let old = helper.output_ports.insert(output_port_key, port_id);
assert!(old.is_none());
Some(DrawingPortsColumn {
ports: vec![DrawingPort {
Expand All @@ -511,14 +517,11 @@ impl<'a, 'h, PortKey: Ord + Copy + Debug, PathKey: Eq + Ord + Copy + Debug>
output_path: _,
output_port_size,
} => {
let input_port_id = DrawingPortId::from(self.helper.port_count);
let output_port_id = DrawingPortId::from(self.helper.port_count + 1);
self.helper.port_count += 2;
self.helper.push_edge(&edge_tail, input_port_id, input_path);
let old = self
.helper
.output_ports
.insert(output_port_key, output_port_id);
let input_port_id = DrawingPortId::from(helper.port_count);
let output_port_id = DrawingPortId::from(helper.port_count + 1);
helper.port_count += 2;
helper.push_edge(&edge_tail, input_port_id, input_path);
let old = helper.output_ports.insert(output_port_key, output_port_id);
assert!(old.is_none());
Some(DrawingPortsColumn {
ports: vec![
Expand Down
40 changes: 20 additions & 20 deletions quirky_binder/src/drawing/graph/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ struct RecordsDrawingVisitor<'a> {

impl<'a> RecordsDrawingVisitor<'a> {
fn input_stream(
graph: &'a Graph,
ports: &mut NodePortsBuilder<'a, '_, RecordsPortKey<'a>, RecordsPathKey<'a>>,
&mut self,
ports: &mut NodePortsBuilder<RecordsPortKey<'a>, RecordsPathKey<'a>>,
stream: &'a NodeStream,
) {
let source = drawing_source_node_name(stream);
let record_definition = &graph.record_definitions()[stream.record_type()];
let record_definition = &self.graph.record_definitions()[stream.record_type()];
let variant = &record_definition[stream.variant_id()];

for d in variant.data() {
Expand All @@ -41,18 +41,18 @@ impl<'a> RecordsDrawingVisitor<'a> {
);

if let Some(sub_stream) = stream.sub_streams().get(&d) {
Self::input_sub_stream(graph, ports, sub_stream, source);
self.input_sub_stream(ports, sub_stream, source);
}
}
}

fn input_sub_stream(
graph: &'a Graph,
ports: &mut NodePortsBuilder<'a, '_, RecordsPortKey<'a>, RecordsPathKey<'a>>,
&mut self,
ports: &mut NodePortsBuilder<RecordsPortKey<'a>, RecordsPathKey<'a>>,
stream: &'a NodeSubStream,
source: &'a [Box<str>],
) {
let record_definition = &graph.record_definitions()[stream.record_type()];
let record_definition = &self.graph.record_definitions()[stream.record_type()];
let variant = &record_definition[stream.variant_id()];

for d in variant.data() {
Expand All @@ -63,18 +63,18 @@ impl<'a> RecordsDrawingVisitor<'a> {
);

if let Some(sub_stream) = stream.sub_streams().get(&d) {
Self::input_sub_stream(graph, ports, sub_stream, source);
self.input_sub_stream(ports, sub_stream, source);
}
}
}

fn output_stream(
graph: &'a Graph,
ports: &mut NodePortsBuilder<'a, '_, RecordsPortKey<'a>, RecordsPathKey<'a>>,
&mut self,
ports: &mut NodePortsBuilder<RecordsPortKey<'a>, RecordsPathKey<'a>>,
stream: &'a NodeStream,
) {
let source = drawing_source_node_name(stream);
let record_definition = &graph.record_definitions()[stream.record_type()];
let record_definition = &self.graph.record_definitions()[stream.record_type()];
let variant = &record_definition[stream.variant_id()];

for d in variant.data() {
Expand All @@ -85,18 +85,18 @@ impl<'a> RecordsDrawingVisitor<'a> {
);

if let Some(sub_stream) = stream.sub_streams().get(&d) {
Self::output_sub_stream(graph, ports, sub_stream, source);
self.output_sub_stream(ports, sub_stream, source);
}
}
}

fn output_sub_stream(
graph: &'a Graph,
ports: &mut NodePortsBuilder<'a, '_, RecordsPortKey<'a>, RecordsPathKey<'a>>,
&mut self,
ports: &mut NodePortsBuilder<RecordsPortKey<'a>, RecordsPathKey<'a>>,
stream: &'a NodeSubStream,
source: &'a [Box<str>],
) {
let record_definition = &graph.record_definitions()[stream.record_type()];
let record_definition = &self.graph.record_definitions()[stream.record_type()];
let variant = &record_definition[stream.variant_id()];

for d in variant.data() {
Expand All @@ -107,7 +107,7 @@ impl<'a> RecordsDrawingVisitor<'a> {
);

if let Some(sub_stream) = stream.sub_streams().get(&d) {
Self::output_sub_stream(graph, ports, sub_stream, source);
self.output_sub_stream(ports, sub_stream, source);
}
}
}
Expand All @@ -122,17 +122,17 @@ impl<'a> Visit<'a> for RecordsDrawingVisitor<'a> {

let (col, row) = self.helper.make_room_for_node(node);

let mut ports = self.helper.node_ports_builder();
let mut ports = NodePortsBuilder::default();

for input in node.inputs() {
Self::input_stream(self.graph, &mut ports, input);
self.input_stream(&mut ports, input);
}

for output in node.outputs() {
Self::output_stream(self.graph, &mut ports, output);
self.output_stream(&mut ports, output);
}

let port_columns = ports.build();
let port_columns = ports.build(&mut self.helper);

self.helper
.push_node_into_column(col, row, node, port_columns);
Expand Down
Loading

0 comments on commit 80e221a

Please sign in to comment.