daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::collections::VecDeque;
  2. use rand::rngs::SmallRng;
  3. use rand::FromEntropy;
  4. use rand::Rng;
  5.  
  6. struct Node {
  7.     id: u16,
  8.     frame_gen_prob: f64,
  9.     buffer: VecDeque<usize>,
  10.     buffer_cap: usize,
  11. }
  12.  
  13. impl Node {
  14.     fn new(id: u16, frame_gen_prob: f64, buffer_cap: usize) -> Node {
  15.         Node {
  16.             id: id,
  17.             frame_gen_prob: frame_gen_prob,
  18.             buffer: VecDeque::with_capacity(buffer_cap),
  19.             buffer_cap: buffer_cap,
  20.         }
  21.     }
  22.  
  23.     fn tick(&mut self, message: usize, rand_source: &mut SmallRng) {
  24.         if self.buffer.len() < self.buffer_cap {
  25.             if rand_source.gen_bool(self.frame_gen_prob) {
  26.                 self.buffer.push_front(message);
  27.             }
  28.         }
  29.     }
  30.  
  31.     fn broadcast(&mut self) -> Option<usize> {
  32.         self.buffer.pop_back()
  33.     }
  34. }
  35.  
  36. fn simulate_single_broadcaster_delays(
  37.     nodes: &mut Vec<Node>,
  38.     step_count: usize,
  39. ) -> Vec<(u16, Option<usize>)> {
  40.     let mut rand_source = SmallRng::from_entropy();
  41.     for step in 0..step_count {
  42.         for node in nodes.iter_mut() {
  43.             node.tick(step, &mut rand_source);
  44.         }
  45.     }
  46.  
  47.     vec![]
  48. }
  49.  
  50. fn main() {
  51.     println!("Hi mom!");
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top