use crate::query;
use super::blocks::{compact_block, ref_kind_block_if_any};
use super::markers::source_suffix;
pub(super) fn inbound_blocks(out: &mut Vec<String>, tables: &query::TsTables<query::InboundRow>) {
for (kind, table) in tables.named() {
ref_kind_block_if_any(out, kind, table, |r: &query::InboundRow| {
format!("{}:{} {kind}{}", r.file, r.line, source_suffix(&r.source))
});
}
}
pub(super) fn outbound_blocks(out: &mut Vec<String>, tables: &query::TsTables<query::OutboundRow>) {
for (kind, table) in tables.named() {
ref_kind_block_if_any(out, kind, table, |r: &query::OutboundRow| {
format!(
"{}:{} {kind} -> {}{}",
r.file,
r.line,
r.to,
source_suffix(&r.source)
)
});
}
}
pub(super) fn compact_blocks<R>(
out: &mut Vec<String>,
direction: &str,
tables: &query::TsTables<R>,
file_of: fn(&R) -> &str,
line_of: fn(&R) -> usize,
) {
for (kind, table) in tables.named() {
compact_block(
out,
&format!("{direction}:{kind}"),
Some(table),
file_of,
|r| line_of(r).to_string(),
);
}
}
pub(super) fn sums<R>(tables: &query::TsTables<R>) -> (usize, usize, usize) {
tables
.named()
.into_iter()
.fold((0, 0, 0), |(total, shown, dropped), (_, t)| {
(total + t.total, shown + t.rows.len(), dropped + t.dropped)
})
}