28 lines
626 B
Rust
28 lines
626 B
Rust
|
|
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<ExprAst>, Box<ExprAst>), // g ∘ f
|
||
|
|
Junction(Box<ExprAst>, Box<ExprAst>), // (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()
|
||
|
|
}
|