mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-12 20:21:01 +00:00
Handle removing a node, and a shard disconnecting (bulk remove)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user