Tree

Struct Tree 

Source
pub struct Tree { /* private fields */ }
Expand description

Tree of Collections for saving to a file.

Implementations§

Source§

impl Tree

Source

pub fn new(name: &str) -> Tree

Returns new Tree

Name is the only required metadata.

§Arguments
  • name - string
§Example
use calcify::Tree;
use calcify::Collection;
use calcify::Bin;
use calcify::ThreeVec;

let f_col: Collection<f64> = Collection::from(vec![0.0,0.0]);
let mut v3_col: Collection<ThreeVec> = Collection::empty();
for _i in 0..9999 {v3_col.push(ThreeVec::random(1.0));}
let col_hist: Collection<Bin> = v3_col.map(ThreeVec::r).hist(50);
let mut ttree = Tree::new("Test_Tree");
ttree.add_field("Desc", "This is a Tree for testing.");
ttree.add_branch("fcol", f_col, "f64");
ttree.add_branch("col_3v", v3_col, "ThreeVec");
ttree.add_branch("hist_3v", col_hist, "Bin");
Source

pub fn add_field(&mut self, key: &str, f: &str) -> Result<(), CalcifyError>

Source

pub fn add_branch<T: 'static + Serializable>( &mut self, key: &str, b: Collection<T>, t: &str, ) -> Result<(), CalcifyError>

Inserts new branch into Tree.

§Arguments
  • key - Hash key, String
  • b - Branch, Collection<T: Serializable>
  • t - Collection subtype, String, one of “f64”, “String”, “ThreeVec”, “ThreeMat”, “FourVec”, “FourMat”, “Bin”, “Point”, “Object”
§Panics
  • t is invalid
Source

pub fn get_branch(&mut self, key: &str) -> Option<&mut Branch>

Returns Branch from a Trees

§Arguments

key - String

§Example
use calcify::Tree;
use calcify::Collection;
use calcify::Bin;

let f_col: Collection<f64> = Collection::from(vec![0.0,0.0]);
let b_col: Collection<Bin> = Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]);
let mut ttree = Tree::new("Test_Tree");
ttree.add_branch("fcol", f_col, "f64").expect("KeyError");
ttree.add_branch("bCol", b_col, "Bin").expect("KeyError");

let ex_f_col: Collection<f64> = ttree.get_branch("fcol").unwrap().extract().unwrap();
let mut ex_b_col: Collection<Bin> = ttree.get_branch("bCol").unwrap().extract().unwrap();

assert_eq!(Collection::from(vec![0.0,0.0]),ex_f_col);
assert_eq!(Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]),ex_b_col);
Source

pub fn read_branch<T: Serializable + Deserializable>( &mut self, key: &str, ) -> Result<Collection<T>, CalcifyError>

Returns Collection from a Trees

§Arguments

key - String

§Example
use calcify::Tree;
use calcify::Collection;
use calcify::Bin;

let f_col: Collection<f64> = Collection::from(vec![0.0,0.0]);
let b_col: Collection<Bin> = Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]);
let mut ttree = Tree::new("Test_Tree");
ttree.add_branch("fcol", f_col, "f64").expect("KeyError");
ttree.add_branch("bCol", b_col, "Bin").expect("KeyError");

let ex_f_col: Collection<f64> = ttree.read_branch("fcol").unwrap();
let mut ex_b_col: Collection<Bin> = ttree.read_branch("bCol").unwrap();
// read from buffer
ex_b_col = ttree.read_branch("bCol").unwrap();

assert_eq!(Collection::from(vec![0.0,0.0]),ex_f_col);
assert_eq!(Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]),ex_b_col);

Trait Implementations§

Source§

impl Deserializable for Tree

Source§

fn from_json(s: &str) -> Result<Self, Box<dyn Error>>

Return Self from string
Source§

fn from_msg(bytes: &[u8]) -> Result<(Self, &[u8]), Box<dyn Error>>

Return a tuple of Self and a &u8 of remaining unparsed bytes from a byte array
Source§

impl FromFile for Tree

Source§

fn read_json(filename: &str) -> Result<Self, Box<dyn Error>>
where Self: Deserializable + Sized,

Read json file to Self.
Source§

fn read_msg(filename: &str) -> Result<Self, Box<dyn Error>>
where Self: Deserializable + Sized,

Read msg file to Self.
Source§

impl Serializable for Tree

Source§

fn to_json(&self) -> String

Return object intensive json string Read more
Source§

fn to_msg(&self) -> Result<Vec<u8>, ValueWriteError>

Return Result wrapped Vec in MsgPack Format is not like to_json it is array intensive not object Read more
Source§

impl ToFile for Tree

Source§

fn write_json(&self, filename: &str) -> Result<(), Box<dyn Error>>
where Self: Serializable,

Write Self as json to file.
Source§

fn write_msg(&self, filename: &str) -> Result<(), Box<dyn Error>>
where Self: Serializable,

Write Self as msg to file.

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl !RefUnwindSafe for Tree

§

impl !Send for Tree

§

impl !Sync for Tree

§

impl Unpin for Tree

§

impl !UnwindSafe for Tree

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.