use std::fmt;
use symbolic_expressions::Sexp;
use fmt::{Debug, Display, Formatter};
#[allow(unused_imports)]
use crate::*;
pub use symbol_table::GlobalSymbol as Symbol;
pub(crate) type BuildHasher = fxhash::FxBuildHasher;
pub(crate) type HashMap<K, V> = hashbrown::HashMap<K, V, BuildHasher>;
pub(crate) type HashSet<K> = hashbrown::HashSet<K, BuildHasher>;
pub(crate) type IndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasher>;
pub(crate) type IndexSet<K> = indexmap::IndexSet<K, BuildHasher>;
pub(crate) type Instant = instant::Instant;
pub(crate) type Duration = instant::Duration;
pub(crate) fn concat_vecs<T>(to: &mut Vec<T>, mut from: Vec<T>) {
if to.len() < from.len() {
std::mem::swap(to, &mut from)
}
to.extend(from);
}
pub(crate) fn pretty_print(
buf: &mut String,
sexp: &Sexp,
width: usize,
level: usize,
) -> std::fmt::Result {
use std::fmt::Write;
if let Sexp::List(list) = sexp {
let indent = sexp.to_string().len() > width;
write!(buf, "(")?;
for (i, val) in list.iter().enumerate() {
if indent && i > 0 {
writeln!(buf)?;
for _ in 0..level {
write!(buf, " ")?;
}
}
pretty_print(buf, val, width, level + 1)?;
if !indent && i < list.len() - 1 {
write!(buf, " ")?;
}
}
write!(buf, ")")?;
Ok(())
} else {
write!(buf, "{}", sexp.to_string().trim_matches('"'))
}
}
pub(crate) struct DisplayAsDebug<T>(pub T);
impl<T: Display> Debug for DisplayAsDebug<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}