pub struct PreTrust {
pub peer: usize,
pub weight: f64,
}Expand description
A seed peer: someone trusted before any local trust is considered.
Pre-trust weights are relative and scaled to sum to 1. Trust flows out from these peers,
and every iteration returns a share alpha of it to them.
use eigentrust::PreTrust;
assert_eq!(PreTrust::new(0, 1.0), (0, 1.0).into());Fields§
§peer: usizeThe seed peer.
weight: f64How much it is trusted. Finite and non-negative.
Implementations§
Source§impl PreTrust
impl PreTrust
Sourcepub const fn new(peer: usize, weight: f64) -> Self
pub const fn new(peer: usize, weight: f64) -> Self
Creates a pre-trust entry.
Examples found in repository?
examples/basic.rs (line 17)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let names = ["alice", "bob", "carol", "mallory"];
7
8 // who trusts whom, and how much (weights are relative per truster)
9 let local_trust = [
10 TrustEdge::new(0, 1, 3.0), // alice -> bob
11 TrustEdge::new(0, 2, 1.0), // alice -> carol
12 TrustEdge::new(1, 2, 2.0), // bob -> carol
13 TrustEdge::new(2, 0, 1.0), // carol -> alice
14 TrustEdge::new(3, 3, 9.0), // mallory only vouches for herself
15 ];
16 // alice is trusted from the start
17 let pre_trust = [PreTrust::new(0, 1.0)];
18
19 let result = eigentrust(local_trust, pre_trust)?;
20
21 for (peer, score) in result.ranking() {
22 println!("{:<8} {:.4}", names[peer], score);
23 }
24 println!("converged after {} iterations", result.iterations());
25 Ok(())
26}Trait Implementations§
impl Copy for PreTrust
impl StructuralPartialEq for PreTrust
Auto Trait Implementations§
impl Freeze for PreTrust
impl RefUnwindSafe for PreTrust
impl Send for PreTrust
impl Sync for PreTrust
impl Unpin for PreTrust
impl UnsafeUnpin for PreTrust
impl UnwindSafe for PreTrust
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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