1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! # Fast Expression Evaluators
//!
//! The fastest expression evaluators
//!
//! ## Introduction
//!
//! ```rust
//! use fee::{prelude::*, DefaultResolver};
//!
//! let mut var_resolver = DefaultResolver::empty();
//! var_resolver.insert("p0", 10.0);
//! var_resolver.insert("p1", 4.0);
//!
//! let mut fn_resolver = DefaultResolver::empty();
//! fn_resolver.insert("abs", ExprFn::new(abs));
//!
//! let context = Context::new(var_resolver, fn_resolver);
//! let mut stack = Vec::with_capacity(10);
//!
//! let expr = Expr::compile("abs((2 + 4) * 6 / (p1 + 2)) + abs(-2)", &context).unwrap();
//! let result = expr.eval(&context, &mut stack).unwrap();
//! assert_eq!(result, 8.0);
//!
//! fn abs(x: &[f64]) -> f64 {
//! x[0].abs()
//! }
//! ```
//!
//! ## Expression
//! A generic struct representing a mathematical expression.
//! Use [`Expr::<T>::compile`] to parse a string into a specialized [`Expr<T>`] depending
//! on the provided [`Context`].
//!
//! ## Context
//! A struct that holds resolvers for variables and functions used in an expression.
//! Contexts can be **locked** to prevent reallocation of inner resolvers, allowing
//! expressions to be evaluated using raw pointers instead of name lookups for maximum performance.
//!
//! ## Resolvers
//! A [`Resolver`] maps variable or function names to their values/implementations.
//! Available resolvers include:
//!
//! - [`DefaultResolver`]: No size or naming restrictions, but slower than specialized resolvers.
//! - [`IndexedResolver`]: No size restrictions, but requires specific naming patterns. Very fast.
//! - [`SmallResolver`]: Restricted size, but allows arbitrary names with good performance.
//! - [`ConstantResolver`]: Always resolves to the same value; offers the best performance.
//! - [`EmptyResolver`]: Always resolves to `None`; useful for expressions without variables or functions.
use Deref;
pub use crate;
pub use crate*;
pub use crate;
pub use crate;
);