pub struct PeerScoreboard { /* private fields */ }Expand description
Composite peer scoreboard.
Maintains per-peer scores across multiple weighted components and provides ranking, decay, and statistics.
Implementations§
Source§impl PeerScoreboard
impl PeerScoreboard
Sourcepub fn new(decay_rate: f64) -> Self
pub fn new(decay_rate: f64) -> Self
Create a new scoreboard with the given per-tick decay rate.
decay_rate is clamped to [0.0, 1.0].
Sourcepub fn register_component(&mut self, name: &str, default_weight: f64)
pub fn register_component(&mut self, name: &str, default_weight: f64)
Register (or update the default weight of) a scoring component.
Sourcepub fn update_score(&mut self, peer_id: &str, component: &str, value: f64)
pub fn update_score(&mut self, peer_id: &str, component: &str, value: f64)
Update a single component score for peer_id.
value is clamped to [0.0, 1.0]. If the component has not been
registered the call is silently ignored.
Sourcepub fn get_score(&self, peer_id: &str) -> Option<f64>
pub fn get_score(&self, peer_id: &str) -> Option<f64>
Return the composite score for peer_id, if tracked.
Sourcepub fn get_component(&self, peer_id: &str, component: &str) -> Option<f64>
pub fn get_component(&self, peer_id: &str, component: &str) -> Option<f64>
Return the value of a single component for peer_id.
Sourcepub fn rank_peers(&self) -> Vec<(String, f64)>
pub fn rank_peers(&self) -> Vec<(String, f64)>
Return all peers ranked by composite score (descending).
Sourcepub fn top_peers(&self, n: usize) -> Vec<(String, f64)>
pub fn top_peers(&self, n: usize) -> Vec<(String, f64)>
Return the top n peers by composite score (descending).
Sourcepub fn apply_decay(&mut self)
pub fn apply_decay(&mut self)
Multiply all component values by decay_rate and recompute composites.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Remove a peer from the scoreboard. Returns true if the peer existed.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Number of tracked peers.
Sourcepub fn stats(&self) -> ScoreboardStats
pub fn stats(&self) -> ScoreboardStats
Snapshot statistics for the entire scoreboard.
Sourcepub fn current_tick(&self) -> u64
pub fn current_tick(&self) -> u64
Return the current tick value.
Trait Implementations§
Source§impl Clone for PeerScoreboard
impl Clone for PeerScoreboard
Source§fn clone(&self) -> PeerScoreboard
fn clone(&self) -> PeerScoreboard
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PeerScoreboard
impl RefUnwindSafe for PeerScoreboard
impl Send for PeerScoreboard
impl Sync for PeerScoreboard
impl Unpin for PeerScoreboard
impl UnsafeUnpin for PeerScoreboard
impl UnwindSafe for PeerScoreboard
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more