Attempt to reduce additional manual comparison upon resume

quickdudley
Jan 21, 2022, 10:07 AM
5OUVESUQDAEU3PEYFDXDMEULBNBJYEEHWV2LWFOOUKCTKRSZQMSAC

Dependencies

  • [2] AOO3FCSG Cargo clippy, tweaks, etc
  • [3] QEKHTVB7 Get most things semi-working except the final sort
  • [4] LLFG625I Should be all the database functions I need
  • [5] CYDK6S5L Fix bugs
  • [*] 5Y7ZXB53 Start picker UI
  • [*] HMOBTVJ4 Initialize crate and add expected dependencies
  • [*] YCWYAX6K Functions for scraping names integrated enough to test (they don't work yet)
  • [*] RNW6D777 Minor tidy

Change contents

  • edit in src/pick.rs at line 1
    [7.32]
    [3.0]
    use crate::depth_check::depths;
  • edit in src/pick.rs at line 56
    [3.1014]
    [3.1014]
    let pdb = db.clone();
  • edit in src/pick.rs at line 58
    [3.1043]
    [3.1043]
    // If this task fails the worst that will happen is I compare more
    // names than I otherwise would. .
    let check =
    tokio::spawn(async move {
    let prefs =
    pdb.list_preferences().await.unwrap_or_else(|_| Vec::new());
    tokio::task::spawn_blocking(move || {
    depths(prefs.into_iter().map(|(better, worse)| {
    (better as usize, worse as usize)
    }))
    })
    .await
    .unwrap_or_else(|_| Vec::new())
    });
  • replacement in src/pick.rs at line 73
    [3.1077][3.1077:1379]()
    for name in db
    .list_names()
    .await
    .ok()
    .into_iter()
    .flat_map(Vec::into_iter)
    {
    match ntx.send(name).await {
    Ok(_) => (),
    Err(_) => break,
    [3.1077]
    [3.1379]
    let names = db.list_names().await;
    let depth_list = check.await.unwrap_or_else(|_| Vec::new());
    for name in names.ok().into_iter().flat_map(Vec::into_iter) {
    if depth_list.get(name.1 as usize).cloned().unwrap_or(0)
    < count.into()
    {
    match ntx.send(name).await {
    Ok(_) => (),
    Err(_) => break,
    }
  • replacement in src/pick.rs at line 116
    [3.2451][2.1183:1273]()
    let pivot: *mut IDedName =
    unsafe { i.offset(j.offset_from(i) / 2) };
    [3.2451]
    [3.2523]
    let pivot: *mut IDedName = unsafe { i.offset(j.offset_from(i) / 2) };
  • edit in src/main.rs at line 3
    [9.33]
    [10.210]
    mod depth_check;
  • file addition: depth_check.rs (----------)
    [8.15]
    pub fn depths<I: IntoIterator<Item = (usize, usize)>>(
    preferences: I,
    ) -> Vec<usize> {
    let mut workspace = Vec::new();
    let mut result = Vec::new();
    for (better, worse) in preferences {
    while workspace.len() <= worse {
    workspace.push(Vec::new());
    result.push(0);
    }
    workspace[worse].push(better);
    }
    let mut stack: Vec<(usize, Option<usize>)> =
    (0..workspace.len()).rev().map(|x| (x, None)).collect();
    while let Some((i, r)) = stack.pop() {
    let d = std::mem::take(&mut workspace[i]);
    if !d.is_empty() {
    stack.push((i, r));
    for j in d {
    stack.push((j, Some(i)));
    }
    } else if let Some(s) = r {
    result[s] = result[s].max(result[i] + 1);
    }
    }
    result
    }