Struct xstack_kad::kbucket::KBucketTable

source ·
pub struct KBucketTable<Key, Value, const K: usize>
where Key: KBucketKey,
{ /* private fields */ }

Implementations§

source§

impl<Key, Value, const K: usize> KBucketTable<Key, Value, K>
where Key: KBucketKey,

source

pub fn const_k() -> usize

Returns the const k value of the k-bucket.

source

pub fn new(local_key: Key) -> Self

Create a new KBucketsTable instance with local key value.

source

pub fn k(&self) -> usize

Return the parameter K of k-bucket.

source

pub fn local_key(&self) -> &Key

Returns the local node key.

source

pub fn len(&self) -> usize

Get the count of stored keys.

source

pub fn get(&self, key: &Key) -> Option<&Value>
where Key: PartialEq,

Returns value of given key.

source

pub fn insert<Q>(&mut self, key: Q, value: Value) -> Option<(Key, Value)>
where Key: From<Q> + PartialEq,

Push value into k-bucket’s bottom. and pop the LRU value from the k-bucket’s top if the k-bucket is full.

This function has no side effects if called with local_key.

source

pub fn remove(&mut self, key: &Key) -> Option<Value>
where Key: PartialEq,

Remove the keypair from the table.

Returns None, if the key is not exists.

source

pub fn closest_k(&self, target: &Key) -> KBucketTableIter<'_, Key, Value, K>

Returns an iterator of up to k keys closest to target.

source

pub fn iter(&self) -> KBucketTableIter<'_, Key, Value, K>

Returns an iterator over all inserted keys.

source

pub fn bucket_of_key(&self, key: &Key) -> Option<&KBucket<Key, Value>>

Get bucket of one key.

Auto Trait Implementations§

§

impl<Key, Value, const K: usize> Freeze for KBucketTable<Key, Value, K>

§

impl<Key, Value, const K: usize> RefUnwindSafe for KBucketTable<Key, Value, K>

§

impl<Key, Value, const K: usize> Send for KBucketTable<Key, Value, K>
where Key: Send, Value: Send,

§

impl<Key, Value, const K: usize> Sync for KBucketTable<Key, Value, K>
where Key: Sync, Value: Sync,

§

impl<Key, Value, const K: usize> Unpin for KBucketTable<Key, Value, K>
where Key: Unpin, <<Key as KBucketKey>::Length as ArrayLength>::ArrayType<Option<usize>>: Unpin, Value: Unpin,

§

impl<Key, Value, const K: usize> UnwindSafe for KBucketTable<Key, Value, K>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more