Is there something for generating the least unique ID available? Something along the lines of...
pub struct UniqueIdsU64 {
ids: Vec<u64>,
}
impl UniqueIdsU64 {
pub fn add(&mut self) -> u64 {
let ids = self.ids;
let n = ids.len();
let last_id_index = n - 1;
let mut semilast_id: Option<u64> = None;
let mut last_id: Option<u64> = None;
for i in 0..n {
if i == last_id_index {
semilast_id = last_id;
last_id = ids.get(i).map(|id| *id);
} else {
semilast_id = Some(ids[i]);
last_id = ids.get(i + 1).map(|id| *id);
}
let next_id = ids[i + 1];
}
if let Some(semilast_id) = semilast_id {
//
} else if let Some(last_id) = last_id {
if 0 == last_id {
let id = last_id + 1;
self.ids.push(id);
return id;
} else {
self.ids.insert(0, 0);
return 0;
}
} else {
self.ids.push(0);
return 0;
}
}
pub fn all(&self) -> Vec<u64> {
self.ids.clone()
}
pub fn clear(&mut self) {
self.ids.clear();
}
pub fn remove(&mut self, id: u64) -> bool {
...
}
}