fix: move rustc profiles to root cargo.toml

This commit is contained in:
max_richter 2024-04-13 12:20:41 +02:00
parent 644bcd6997
commit 5701c51bd6
13 changed files with 144 additions and 4955 deletions

4931
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = ["app/src-tauri", "nodes/max/plantarium/*", "packages/plantarium"] members = ["nodes/max/plantarium/*", "packages/plantarium"]
[profile.release] [profile.release]
lto = true lto = true
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -13,6 +13,8 @@
console.log("ENCODED"); console.log("ENCODED");
console.log(encoded); console.log(encoded);
encoded = [0, 2, 1, 0, 4, 4, 2, 4, 1, 2, 2, 0, 3, 2, 3, 1, 1, 1, 1];
const decoded = decode(encoded); const decoded = decode(encoded);
console.log("DECODED"); console.log("DECODED");
console.log(decoded); console.log(decoded);

View File

@ -24,7 +24,3 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -24,7 +24,3 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -19,7 +19,3 @@ plantarium = { version = "0.1.0", path = "../../../../packages/plantarium" }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -25,7 +25,3 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -24,7 +24,3 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -24,7 +24,3 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -24,7 +24,3 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.34" wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -0,0 +1,38 @@
pub fn encode_float(f: f32) -> (i32, i32) {
let bits = f.to_bits();
let mantissa = (bits & 0x007FFFFF) as i32;
let exponent = ((bits >> 23) & 0xFF) as i32;
let sign = if f < 0.0 { 1 } else { 0 }; // Determine sign as 1 for negative, 0 for positive
(mantissa | (sign << 23), exponent) // Include the sign bit in the mantissa
}
pub fn decode_float(mantissa: i32, exponent: i32) -> f32 {
let sign_bit = ((mantissa >> 23) & 1) as u32; // Extract the sign bit
let mantissa_bits = (mantissa & 0x007FFFFF) as u32;
let exponent_bits = (exponent as u32 & 0xFF) << 23;
let bits = (sign_bit << 31) | exponent_bits | mantissa_bits; // Reconstruct all bits including sign
f32::from_bits(bits)
}
#[cfg(test)]
mod tests {
use super::*;
#[rustfmt::skip]
#[test]
fn test_encode_decode() {
let original_floats = [
0.0, 1.0, -1.0, 123.456, -123.456, 1e-10, -1e10, f32::MAX, f32::MIN,
];
for &original in &original_floats {
let (mantissa, exponent) = encode_float(original);
let decoded = decode_float(mantissa, exponent);
assert!(
(decoded - original).abs() < 1e-6,
"Mismatch: original {} vs decoded {}",
original,
decoded
);
}
}
}

View File

@ -1,2 +1,4 @@
mod helpers; mod helpers;
mod tree;
pub use helpers::*; pub use helpers::*;
pub use tree::*;

View File

@ -0,0 +1,94 @@
pub fn get_arg<'a>(index: i32, args: &'a Vec<i32>) -> Option<&'a [i32]> {
let mut arg_index = -1;
let mut i: usize = 0;
let mut depth = 0;
let mut arg_start_index = 0;
let mut next_bracket_index = 0;
while i < args.len() {
println!("------");
let is_bracket = i == next_bracket_index;
let value = args[i];
// if we are at a bracket
if is_bracket {
next_bracket_index = 1 + i + args[i + 1] as usize;
// if is opening
if value == 0 {
if i != 0 {
depth += 1;
}
if depth == 0 {
i += 2;
arg_index += 1;
} else {
i = next_bracket_index;
}
// if closing
} else if value == 1 {
depth -= 1;
if depth > 1 {
i = next_bracket_index;
} else {
i += 2;
}
}
continue;
}
arg_index += 1;
println!(
"i: {}, next: {}, v: {}, ai: {}",
i, next_bracket_index, args[i], arg_index
);
println!("is_bracket: {}", is_bracket);
println!("depth: {}", depth);
println!("arg_start_index: {}", arg_start_index);
if arg_index == index {
println!("------");
return Some(&args[arg_start_index..=i]);
}
i += 1;
}
None
}
fn main() {
let input_a = vec![0, 4, 1, 2, 3, 0, 7, 1, 2, 4, 2, 4, 1, 1, 1, 1];
// -> [1, 2, 3, [1, 2, 4, 2, 4]]
// 1: [1]
// 2: [2]
// 3: [3]
// 4: [1,2,4,2,4]
let input_b = vec![0, 2, 1, 0, 4, 4, 2, 4, 1, 2, 2, 0, 3, 2, 3, 1, 1, 1, 1];
// -> [1,[4,2,4], 2, [2,3]];
// 1: [1]
// 2: [4,2,4]
// 3: [2]
// 4: [2,3]
let input = input_b;
//let first_arg = get_arg(0, &input);
//println!("-----> FIRST: {:?}", first_arg);
//let second_arg = get_arg(1, &input);
//println!("-----> SECOND: {:?}", second_arg);
//let third_arg = get_arg(2, &input);
//println!("-----> THIRD: {:?}", third_arg);
let fourth_arg = get_arg(3, &input);
println!("-----> FOURTH: {:?}", fourth_arg);
}