rust/hg-core/src/discovery.rs
changeset 44042 2abffea40700
parent 43826 5ac243a92e37
child 44599 d31d1c0685be
equal deleted inserted replaced
44041:fa808e65eabb 44042:2abffea40700
    16 use rand::{thread_rng, RngCore, SeedableRng};
    16 use rand::{thread_rng, RngCore, SeedableRng};
    17 use std::cmp::{max, min};
    17 use std::cmp::{max, min};
    18 use std::collections::{HashSet, VecDeque};
    18 use std::collections::{HashSet, VecDeque};
    19 
    19 
    20 type Rng = rand_pcg::Pcg32;
    20 type Rng = rand_pcg::Pcg32;
       
    21 type Seed = [u8; 16];
    21 
    22 
    22 pub struct PartialDiscovery<G: Graph + Clone> {
    23 pub struct PartialDiscovery<G: Graph + Clone> {
    23     target_heads: Option<Vec<Revision>>,
    24     target_heads: Option<Vec<Revision>>,
    24     graph: G, // plays the role of self._repo
    25     graph: G, // plays the role of self._repo
    25     common: MissingAncestors<G>,
    26     common: MissingAncestors<G>,
   156         graph: G,
   157         graph: G,
   157         target_heads: Vec<Revision>,
   158         target_heads: Vec<Revision>,
   158         respect_size: bool,
   159         respect_size: bool,
   159         randomize: bool,
   160         randomize: bool,
   160     ) -> Self {
   161     ) -> Self {
   161         let mut seed: [u8; 16] = [0; 16];
   162         let mut seed = [0; 16];
   162         if randomize {
   163         if randomize {
   163             thread_rng().fill_bytes(&mut seed);
   164             thread_rng().fill_bytes(&mut seed);
   164         }
   165         }
   165         Self::new_with_seed(graph, target_heads, seed, respect_size, randomize)
   166         Self::new_with_seed(graph, target_heads, seed, respect_size, randomize)
   166     }
   167     }
   167 
   168 
   168     pub fn new_with_seed(
   169     pub fn new_with_seed(
   169         graph: G,
   170         graph: G,
   170         target_heads: Vec<Revision>,
   171         target_heads: Vec<Revision>,
   171         seed: [u8; 16],
   172         seed: Seed,
   172         respect_size: bool,
   173         respect_size: bool,
   173         randomize: bool,
   174         randomize: bool,
   174     ) -> Self {
   175     ) -> Self {
   175         PartialDiscovery {
   176         PartialDiscovery {
   176             undecided: None,
   177             undecided: None,