use crate::data::atomic::Word;
use crate::data::composite::Array;
pub struct Words;
impl Words {
pub const fn from_i64(value: i64) -> Word { Word::from_be_bytes(value.to_be_bytes()) }
pub const fn i64(word: Word) -> i64 { i64::from_be_bytes(word.to_be_bytes()) }
pub fn from_f64(value: f64) -> Word { Word::from_be_bytes(value.to_be_bytes()) }
pub fn f64(word: Word) -> f64 { f64::from_be_bytes(word.to_be_bytes()) }
pub fn raw_u32s(word: Word) -> (u32, u32) {
let [l, r] = word.split();
(l.to_u32(), r.to_u32())
}
pub fn raw_u16s(word: Word) -> (u16, u16, u16, u16) {
let [l, r] = word.split();
let l = l .to_u32().to_be_bytes();
let r = r .to_u32().to_be_bytes();
(
u16::from_be_bytes([l[0], l[1]]),
u16::from_be_bytes([l[2], l[3]]),
u16::from_be_bytes([r[0], r[1]]),
u16::from_be_bytes([r[2], r[3]]),
)
}
}
pub struct Arrays;
impl Arrays {
pub fn from_raw(arr: &[u64]) -> Array {
Array::from(&arr.iter().map(|u| Word::new(*u)).collect::<Vec<Word>>())
}
pub fn raw(array: Array) -> Vec<u64> {
array.into_iter().map(|word| word.to_u64()).collect()
}
pub fn from_sizes(arr: &[usize]) -> Array {
Array::from(&arr.iter().map(|u| Word::new(*u as u64)).collect::<Vec<Word>>())
}
pub fn sizes(array: Array) -> Vec<usize> {
array.into_iter().map(|word| word.to_u64() as usize).collect()
}
}