use usize to index working set

This commit is contained in:
Dustin J. Mitchell
2020-11-24 11:52:50 -05:00
parent d84c156782
commit fc668e5ca8
5 changed files with 13 additions and 13 deletions

View File

@@ -108,14 +108,13 @@ impl<'t> TaskStorageTxn for Txn<'t> {
Ok(self.data_ref().working_set.clone())
}
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<u64> {
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<usize> {
let working_set = &mut self.mut_data_ref().working_set;
working_set.push(Some(uuid.clone()));
Ok(working_set.len() as u64)
Ok(working_set.len())
}
fn remove_from_working_set(&mut self, index: u64) -> Fallible<()> {
let index = index as usize;
fn remove_from_working_set(&mut self, index: usize) -> Fallible<()> {
let working_set = &mut self.mut_data_ref().working_set;
if index >= working_set.len() || working_set[index].is_none() {
return Err(format_err!("No task found with index {}", index));

View File

@@ -302,7 +302,7 @@ impl<'t> TaskStorageTxn for Txn<'t> {
Ok(res)
}
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<u64> {
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<usize> {
let working_set_bucket = self.working_set_bucket();
let numbers_bucket = self.numbers_bucket();
let kvtxn = self.kvtxn();
@@ -323,10 +323,11 @@ impl<'t> TaskStorageTxn for Txn<'t> {
NEXT_WORKING_SET_INDEX.into(),
Msgpack::to_value_buf(next_index + 1)?,
)?;
Ok(next_index)
Ok(next_index as usize)
}
fn remove_from_working_set(&mut self, index: u64) -> Fallible<()> {
fn remove_from_working_set(&mut self, index: usize) -> Fallible<()> {
let index = index as u64;
let working_set_bucket = self.working_set_bucket();
let numbers_bucket = self.numbers_bucket();
let kvtxn = self.kvtxn();

View File

@@ -80,10 +80,10 @@ pub trait TaskStorageTxn {
/// Add a task to the working set and return its (one-based) index. This index will be one greater
/// than the highest used index.
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<u64>;
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<usize>;
/// Remove a task from the working set. Other tasks' indexes are not affected.
fn remove_from_working_set(&mut self, index: u64) -> Fallible<()>;
fn remove_from_working_set(&mut self, index: usize) -> Fallible<()>;
/// Clear all tasks from the working set in preparation for a garbage-collection operation.
fn clear_working_set(&mut self) -> Fallible<()>;