pub struct AddressBook<A: Address> { /* private fields */ }Expand description
A bounded, deduplicated collection of addresses for a peer.
Backed by an LRU cache: all operations (insert, lookup, promote, evict) are O(1). Most recently seen addresses are promoted automatically. When capacity is exceeded, the least recently seen entry is evicted.
Implementations§
Source§impl<A: Address> AddressBook<A>
impl<A: Address> AddressBook<A>
pub fn new(first_addr: A, max_size: usize) -> AddressBook<A>
Sourcepub fn seen(&mut self, addr: A) -> bool
pub fn seen(&mut self, addr: A) -> bool
Record that we’ve seen this address. Returns true if it was newly added. If already present, promotes it to most recent. If at capacity, evicts the least recently seen entry.
pub fn get(&self, index: usize) -> Option<&A>
Sourcepub fn iter(&self) -> impl Iterator<Item = &A>
pub fn iter(&self) -> impl Iterator<Item = &A>
Iterates from most recently seen to least recently seen.
pub fn len(&self) -> usize
pub fn max_size(&self) -> usize
pub fn contains(&self, addr: &A) -> bool
pub fn remove(&mut self, addr: &A) -> bool
pub fn is_empty(&self) -> bool
Sourcepub fn concat(&mut self, other: &AddressBook<A>) -> usize
pub fn concat(&mut self, other: &AddressBook<A>) -> usize
Merge addresses from another page into this one. New addresses go in as least recent. Returns number added.
Trait Implementations§
Source§impl<A: Address> Clone for AddressBook<A>
impl<A: Address> Clone for AddressBook<A>
Source§impl<A: Address> Display for AddressBook<A>
impl<A: Address> Display for AddressBook<A>
Source§impl<A: Address> Hash for AddressBook<A>
impl<A: Address> Hash for AddressBook<A>
Source§impl<A: Address> PartialEq for AddressBook<A>
impl<A: Address> PartialEq for AddressBook<A>
impl<A: Address> Eq for AddressBook<A>
Auto Trait Implementations§
impl<A> Freeze for AddressBook<A>
impl<A> RefUnwindSafe for AddressBook<A>where
A: RefUnwindSafe,
impl<A> Send for AddressBook<A>where
A: Send,
impl<A> Sync for AddressBook<A>where
A: Sync,
impl<A> Unpin for AddressBook<A>
impl<A> UnsafeUnpin for AddressBook<A>
impl<A> UnwindSafe for AddressBook<A>where
A: RefUnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.