Handle removing a node, and a shard disconnecting (bulk remove)

This commit is contained in:
James Wilson
2021-06-25 17:21:24 +01:00
parent 4f60453689
commit 89dfad5bbe
6 changed files with 350 additions and 81 deletions
+6 -1
View File
@@ -1,4 +1,4 @@
use std::hash::Hash;
use std::{fmt::Display, hash::Hash};
use serde::{Serialize,Deserialize};
use bimap::BiMap;
@@ -15,6 +15,11 @@ impl std::convert::From<usize> for Id {
Id(n)
}
}
impl Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
/// A struct that allows you to assign an ID to an arbitrary set of
/// details (so long as they are Eq+Hash+Clone), and then access
+7 -1
View File
@@ -10,7 +10,13 @@ pub struct MostSeen<T> {
others: HashMap<T, usize>
}
impl <T: Hash + Eq> MostSeen<T> {
impl <T: Default> Default for MostSeen<T> {
fn default() -> Self {
MostSeen::new(T::default())
}
}
impl <T> MostSeen<T> {
pub fn new(item: T) -> Self {
Self {
current_best: item,
+12
View File
@@ -77,4 +77,16 @@ impl<T> DenseMap<T> {
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Return the next Id that will be assigned.
pub fn next_id(&self) -> usize {
match self.retired.last() {
Some(id) => {
*id
}
None => {
self.items.len()
}
}
}
}