Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::cell::Cell;
- use std::rc::Rc;
- struct Stat {
- name: String,
- cur_mean: f64,
- cur_variance: f64,
- covs: Vec<StatCov>,
- }
- impl Stat {
- fn update(&mut self, time: f64, val: f64) {
- for cov in &self.covs {
- cov.update(time, val);
- }
- }
- }
- #[derive(Clone)]
- struct StatCov {
- inner: Rc<InnerStatCov>,
- }
- impl StatCov {
- fn update(&self, time: f64, val: f64) {
- self.inner.update(time, val);
- }
- }
- #[derive(Default)]
- struct InnerStatCov {
- cur_mean: Cell<f64>,
- cur_variance: Cell<f64>,
- }
- impl InnerStatCov {
- fn update(&self, time: f64, val: f64) {}
- }
- fn main() {
- let shared_cov = StatCov {
- inner: Rc::new(InnerStatCov::default()),
- };
- let stat1 = Stat {
- name: "stat1".into(),
- cur_mean: 0.0,
- cur_variance: 0.0,
- covs: vec![shared_cov.clone()],
- };
- let stat2 = Stat {
- name: "stat2".into(),
- cur_mean: 0.0,
- cur_variance: 0.0,
- covs: vec![shared_cov],
- };
- }
Add Comment
Please, Sign In to add comment