|
|
@ -1,7 +1,9 @@
|
|
|
|
use argon2::{Config, Variant};
|
|
|
|
use argon2::{Config, Variant};
|
|
|
|
|
|
|
|
use cmp::Ordering;
|
|
|
|
use rand::prelude::*;
|
|
|
|
use rand::prelude::*;
|
|
|
|
use sled::IVec;
|
|
|
|
use sled::IVec;
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
|
|
|
|
cmp,
|
|
|
|
convert::TryInto,
|
|
|
|
convert::TryInto,
|
|
|
|
time::{SystemTime, UNIX_EPOCH},
|
|
|
|
time::{SystemTime, UNIX_EPOCH},
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -63,6 +65,7 @@ pub fn calculate_hash(password: &str) -> Result<String, argon2::Error> {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn common_elements(
|
|
|
|
pub fn common_elements(
|
|
|
|
mut iterators: impl Iterator<Item = impl Iterator<Item = IVec>>,
|
|
|
|
mut iterators: impl Iterator<Item = impl Iterator<Item = IVec>>,
|
|
|
|
|
|
|
|
check_order: impl Fn(&IVec, &IVec) -> Ordering,
|
|
|
|
) -> Option<impl Iterator<Item = IVec>> {
|
|
|
|
) -> Option<impl Iterator<Item = IVec>> {
|
|
|
|
let first_iterator = iterators.next()?;
|
|
|
|
let first_iterator = iterators.next()?;
|
|
|
|
let mut other_iterators = iterators.map(|i| i.peekable()).collect::<Vec<_>>();
|
|
|
|
let mut other_iterators = iterators.map(|i| i.peekable()).collect::<Vec<_>>();
|
|
|
@ -72,14 +75,15 @@ pub fn common_elements(
|
|
|
|
.iter_mut()
|
|
|
|
.iter_mut()
|
|
|
|
.map(|it| {
|
|
|
|
.map(|it| {
|
|
|
|
while let Some(element) = it.peek() {
|
|
|
|
while let Some(element) = it.peek() {
|
|
|
|
if element > target {
|
|
|
|
match check_order(element, target) {
|
|
|
|
return false;
|
|
|
|
Ordering::Greater => return false, // We went too far
|
|
|
|
} else if element == target {
|
|
|
|
Ordering::Equal => return true, // Element is in both iters
|
|
|
|
return true;
|
|
|
|
Ordering::Less => {
|
|
|
|
} else {
|
|
|
|
// Keep searching
|
|
|
|
it.next();
|
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
false
|
|
|
|
})
|
|
|
|
})
|
|
|
|