From 3e4bc1e6fc634c321a6a1b3dd5ad600db22a158d Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Sun, 5 Sep 2021 08:28:36 -0700 Subject: [PATCH] Add remove method --- server/src/kvengine/listmap.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/src/kvengine/listmap.rs b/server/src/kvengine/listmap.rs index a338cc4c..18ef6225 100644 --- a/server/src/kvengine/listmap.rs +++ b/server/src/kvengine/listmap.rs @@ -55,15 +55,22 @@ impl KVEListMap { pub fn get_id_encoder(&self) -> SingleEncoder { s_encoder_booled!(self.encoded_id) } + /// Check if the key is encoded correctly pub fn encode_key>(&self, val: T) -> bool { s_encoder!(self.encoded_id)(val.as_ref()) } + /// Check if the element in a list is encoded correctly + pub fn encode_value>(&self, val: T) -> bool { + s_encoder!(self.encoded_id)(val.as_ref()) + } borrow_hash_fn! { + /// Check the length of a list if it exists pub fn {borrow: Data} len(self: &Self, key: &Q) -> Option { self.base.get(key).map(|v| v.read().len()) } } - pub fn add_list(&mut self, listname: Data) -> Option { + /// Create and add a new list to the map + pub fn add_list(&self, listname: Data) -> Option { if_cold! { if (self.encode_key(&listname)) { 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) + } }