From bf56185ca1af8f5109a2f88e207d4153493709af Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Wed, 9 Dec 2020 12:56:16 +0100 Subject: [PATCH] add some operations to VecBuffer --- src/vec_buffer.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/vec_buffer.rs b/src/vec_buffer.rs index b3541f6..4b5445f 100644 --- a/src/vec_buffer.rs +++ b/src/vec_buffer.rs @@ -32,12 +32,36 @@ impl VecBuffer { pub fn push(&mut self, val: T) { self.port.notify({ let mut d = self.data.write().unwrap(); - let len = d.len(); + let idx = d.len(); d.push(val); - len + idx }); } - // TODO: add functions + pub fn remove(&mut self, idx: usize) { + let len = { + let mut d = self.data.write().unwrap(); + let len = d.len(); + d.remove(idx); + len + }; + + for i in idx .. len { + self.port.notify(i); + } + } + + pub fn insert(&mut self, idx: usize, val: T) { + let len = { + let mut d = self.data.write().unwrap(); + d.insert(idx, val); + let len = d.len(); + len + }; + + for i in idx .. len { + self.port.notify(i); + } + } }