use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Prim { Sin, Cos, Triple, // 3 * x AddPair, // (a,b) -> a + b Input, // переменная x } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ExprAst { Atom(Prim), Composition(Box, Box), // g ∘ f Junction(Box, Box), // (f, g) } pub fn ast_input() -> ExprAst { ExprAst::Atom(Prim::Input) } pub fn hash_ast(e: &ExprAst) -> u64 { let mut h = DefaultHasher::new(); e.hash(&mut h); h.finish() }