Skip to content

Commit

Permalink
[storage] Add removal of index from FileIndex #63 (#64)
Browse files Browse the repository at this point in the history
* Update file_index.rs

* Update file_index.rs
  • Loading branch information
michaelvlach authored Aug 21, 2022
1 parent 0fd75d5 commit d7a490e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/storage/file_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl FileIndex {
pub(crate) fn insert(&mut self, index: i64, position: u64) {
self.positions.insert(index, position);
}

pub(crate) fn remove(&mut self, index: i64) {
self.positions.remove(&index);
}
}

#[cfg(test)]
Expand All @@ -27,7 +31,7 @@ mod tests {
}

#[test]
fn insert_indexes_and_positions() {
fn insert_indexes() {
let mut file_index = FileIndex::default();
let index1 = 1_i64;
let index2 = 2_i64;
Expand All @@ -40,4 +44,20 @@ mod tests {
assert_eq!(file_index.get(index1), Some(&pos1));
assert_eq!(file_index.get(index2), Some(&pos2));
}

#[test]
fn remove_index() {
let mut file_index = FileIndex::default();
let index1 = 1_i64;
let index2 = 2_i64;
let pos1 = 32u64;
let pos2 = 64u64;

file_index.insert(index1, pos1);
file_index.insert(index2, pos2);
file_index.remove(index1);

assert_eq!(file_index.get(index1), None);
assert_eq!(file_index.get(index2), Some(&pos2));
}
}

0 comments on commit d7a490e

Please sign in to comment.