mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-18 14:38:10 -07:00
computer: fix stateful
This commit is contained in:
@@ -38,6 +38,30 @@ where
|
||||
self.0.get_or_read(index, mmap)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update_or_push(&mut self, index: I, value: T) -> Result<()> {
|
||||
self.0.update_or_push(index, value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn checked_push(&mut self, index: I, value: T) -> Result<()> {
|
||||
let len = self.0.len();
|
||||
match len.cmp(&index.to_usize()?) {
|
||||
Ordering::Greater => {
|
||||
dbg!(index, value, len, self.0.header());
|
||||
Err(Error::IndexTooLow)
|
||||
}
|
||||
Ordering::Equal => {
|
||||
self.0.push(value);
|
||||
Ok(())
|
||||
}
|
||||
Ordering::Less => {
|
||||
dbg!(index, value, len, self.0.header());
|
||||
Err(Error::IndexTooHigh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push_if_needed(&mut self, index: I, value: T) -> Result<()> {
|
||||
let len = self.0.len();
|
||||
@@ -58,6 +82,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn fill_first_hole_or_push(&mut self, value: T) -> Result<I> {
|
||||
self.0.fill_first_hole_or_push(value)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, index: I, value: T) -> Result<()> {
|
||||
self.0.update(index, value)
|
||||
}
|
||||
|
||||
pub fn take(&mut self, index: I, mmap: &Mmap) -> Result<Option<T>> {
|
||||
self.0.take(index, mmap)
|
||||
}
|
||||
|
||||
pub fn delete(&mut self, index: I) {
|
||||
self.0.delete(index)
|
||||
}
|
||||
|
||||
fn update_height(&mut self, height: Height) {
|
||||
self.0.mut_header().update_height(height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user