pub struct BTree { /* private fields */ }
Expand description
BTree
is where the informatio Sender
is contained.
Its inner implementation has a tuple containing the action to be taken as well as a oneshot channel to receive data.
To start the BTree
thread just execute BTree::start(buffer_size: usize)
. If you buffer_size
is too short
it may cause synchronization problems, so it should be well ajusted to your application needs.
Implementations§
Source§impl BTree
impl BTree
Sourcepub fn start(buffer_size: usize) -> Self
pub fn start(buffer_size: usize) -> Self
BTree::start(buffer_size: usize)
is the entrypoint to start using BTree
methods.
It creates a thread containing the BTreeMap and keeps listening to entries.
Sourcepub async fn insert<V: Into<Types>>(
&self,
k: String,
v: V,
) -> Result<Option<Types>, String>
pub async fn insert<V: Into<Types>>( &self, k: String, v: V, ) -> Result<Option<Types>, String>
Method insert
is equivalent to std::collection::BTreeMap insert
,
it returns None
if the key does not exist and it returns Some(Types::_)
with the previous value,
if the key already exists.
Sourcepub async fn contains(&self, k: String) -> Result<bool, String>
pub async fn contains(&self, k: String) -> Result<bool, String>
Method contains
is equivalent to std::collection::BTreeMap contains_key
,
It checks if a key already exists in the BTree
. If the key exists the return is Ok(true)
,
if it doesn’t exist it returns Ok(false)
Sourcepub async fn get(&self, k: String) -> Result<Option<Types>, String>
pub async fn get(&self, k: String) -> Result<Option<Types>, String>
Method get
is equivalent to std::collection::BTreeMap get
,
It returns the value contained at the key passed as argument. If no key is found the return is Ok(None)
,
else it returns Ok(Some(Types::_))
.
Sourcepub async fn len(&self) -> Result<usize, String>
pub async fn len(&self) -> Result<usize, String>
Method len
is equivalent to std::collection::BTreeMap len
,
It returns the length of the btree as a usize.
Sourcepub async fn keys(&self) -> Result<Vec<String>, String>
pub async fn keys(&self) -> Result<Vec<String>, String>
Method keys
is equivalent to std::collection::BTreeMap keys
,
It returns a vector containing all the keys sorted.
For BTree
the keys are always Strings
.
Sourcepub async fn values(&self) -> Result<Vec<Types>, String>
pub async fn values(&self) -> Result<Vec<Types>, String>
Method values
is equivalent to std::collection::BTreeMap values
,
It returns a vector containing all the values sorted by their respective keys order.
Sourcepub async fn remove(&self, k: String) -> Result<Option<Types>, String>
pub async fn remove(&self, k: String) -> Result<Option<Types>, String>
Method remove
is equivalent to std::collection::BTreeMap remove
,
It returns the value removed from the BTree
for the key passed as argument. If no key is found the return is Ok(None)
,
else it returns Ok(Some(Types::_))
.
Sourcepub async fn remove_entry(&self, k: String) -> Result<Option<Types>, String>
pub async fn remove_entry(&self, k: String) -> Result<Option<Types>, String>
Method remove_entry
is equivalent to std::collection::BTreeMap remove_entry
,
It returns the key and value removed from the BTree
for the key passed as argument as a Option<Types::KeyValue(_,_)>
.
If no key is found the return is Ok(None)
,