tachyon_math_library/state/
mod.rs1use anchor_lang::prelude::*;
2
3pub use function_data::*;
4pub use functions::*;
5
6pub mod function_data;
7pub mod functions;
8
9pub const NUM_VALUES: usize = 200000; pub const FUNCTIONS_SEED: &[u8] = b"functions";
12
13#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Default, Eq, PartialEq)]
14pub enum FunctionType {
15 #[default]
16 None = 0,
17 Exp = 1,
18 Ln = 2,
19 Log10 = 3,
20 Sin = 4,
21 Cos = 5,
22}
23
24impl TryFrom<u32> for FunctionType {
25 type Error = ();
26
27 fn try_from(v: u32) -> std::result::Result<Self, Self::Error> {
28 match v {
29 x if x == FunctionType::None as u32 => Ok(FunctionType::None),
30 x if x == FunctionType::Exp as u32 => Ok(FunctionType::Exp),
31 x if x == FunctionType::Ln as u32 => Ok(FunctionType::Ln),
32 x if x == FunctionType::Log10 as u32 => Ok(FunctionType::Log10),
33 x if x == FunctionType::Sin as u32 => Ok(FunctionType::Sin),
34 x if x == FunctionType::Cos as u32 => Ok(FunctionType::Cos),
35 _ => Err(()),
36 }
37 }
38}
39
40#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Default, Eq, PartialEq)]
41pub enum ValueCode {
42 #[default]
43 Empty = 0,
44 Valid = 1,
45 NaN = 2,
46}
47
48impl TryFrom<u8> for ValueCode {
49 type Error = ();
50
51 fn try_from(v: u8) -> std::result::Result<Self, Self::Error> {
52 match v {
53 x if x == ValueCode::Empty as u8 => Ok(ValueCode::Empty),
54 x if x == ValueCode::Valid as u8 => Ok(ValueCode::Valid),
55 x if x == ValueCode::NaN as u8 => Ok(ValueCode::NaN),
56 _ => Err(()),
57 }
58 }
59}
60
61pub fn reduce_value_codes(rcs_as_u8: Vec<u8>) -> ValueCode {
62 let rcs = rcs_as_u8.into_iter().map(|x| ValueCode::try_from(x).unwrap()).collect::<Vec<ValueCode>>();
63
64 if rcs.contains(&ValueCode::Empty) {
65 ValueCode::Empty
66 } else if rcs.contains(&ValueCode::NaN) {
67 ValueCode::NaN
68 } else {
69 ValueCode::Valid
70 }
71}
72
73#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Default, Eq, PartialEq)]
74pub enum Interpolation {
75 #[default]
76 Linear,
77 Quadratic,
78}