add some operations to VecBuffer
This commit is contained in:
parent
9faaf8e38e
commit
bf56185ca1
1 changed files with 27 additions and 3 deletions
|
@ -32,12 +32,36 @@ impl<T: Clone + Eq + Send + Sync + 'static> VecBuffer<T> {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue