Add remove method

next
Sayan Nandan 3 years ago
parent ef3e617147
commit 3e4bc1e6fc

@ -55,15 +55,22 @@ impl KVEListMap {
pub fn get_id_encoder(&self) -> SingleEncoder { pub fn get_id_encoder(&self) -> SingleEncoder {
s_encoder_booled!(self.encoded_id) s_encoder_booled!(self.encoded_id)
} }
/// Check if the key is encoded correctly
pub fn encode_key<T: AsRef<[u8]>>(&self, val: T) -> bool { pub fn encode_key<T: AsRef<[u8]>>(&self, val: T) -> bool {
s_encoder!(self.encoded_id)(val.as_ref()) s_encoder!(self.encoded_id)(val.as_ref())
} }
/// Check if the element in a list is encoded correctly
pub fn encode_value<T: AsRef<[u8]>>(&self, val: T) -> bool {
s_encoder!(self.encoded_id)(val.as_ref())
}
borrow_hash_fn! { borrow_hash_fn! {
/// Check the length of a list if it exists
pub fn {borrow: Data} len(self: &Self, key: &Q) -> Option<usize> { pub fn {borrow: Data} len(self: &Self, key: &Q) -> Option<usize> {
self.base.get(key).map(|v| v.read().len()) self.base.get(key).map(|v| v.read().len())
} }
} }
pub fn add_list(&mut self, listname: Data) -> Option<bool> { /// Create and add a new list to the map
pub fn add_list(&self, listname: Data) -> Option<bool> {
if_cold! { if_cold! {
if (self.encode_key(&listname)) { if (self.encode_key(&listname)) {
None None
@ -72,4 +79,8 @@ impl KVEListMap {
} }
} }
} }
/// Remove a key from the map
pub fn remove(&self, listname: &[u8]) -> bool {
self.base.true_if_removed(listname)
}
} }

Loading…
Cancel
Save